| author | ymh <ymh.work@gmail.com> |
| Thu, 22 Jun 2017 12:09:48 +0200 | |
| changeset 74 | 043477fd5c5c |
| parent 66 | f402435be429 |
| child 78 | 49c5ea36d0a4 |
| permissions | -rw-r--r-- |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
1 |
import uuidV1 from 'uuid/v1'; |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
2 |
|
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
3 |
import * as types from '../constants/actionTypes'; |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
4 |
|
| 15 | 5 |
export const addNote = (session, data) => { |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
6 |
const noteId = uuidV1(); |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
7 |
const note = { |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
8 |
_id: noteId, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
9 |
session: session._id, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
10 |
raw: data.raw, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
11 |
plain: data.plain, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
12 |
html: data.html, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
13 |
startedAt: data.startedAt, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
14 |
finishedAt: data.finishedAt, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
15 |
categories: data.categories, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
16 |
}; |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
17 |
|
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
18 |
const noteSrvr = { |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
19 |
ext_id: noteId, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
20 |
session: session._id, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
21 |
raw: JSON.stringify(data.raw), |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
22 |
plain: data.plain, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
23 |
html: data.html, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
24 |
tc_start: data.startedAt, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
25 |
tc_end: data.finishedAt, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
26 |
categorization: JSON.stringify(data.categories), |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
27 |
} |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
28 |
|
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
29 |
return { |
|
62
b2514a9bcd49
migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents:
59
diff
changeset
|
30 |
type: types.ADD_NOTE, |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
31 |
note, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
32 |
meta: { |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
33 |
offline: { |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
34 |
effect: { |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
35 |
url: `/api/notes/sessions/${session.get('_id')}/notes/`, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
36 |
method: 'POST', |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
37 |
data: noteSrvr |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
38 |
}, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
39 |
commit: { type: types.NOOP }, |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
40 |
rollback: { type: types.NOOP } |
|
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
41 |
} |
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
42 |
} |
|
74
043477fd5c5c
add api call to save notes. internally use ts for time data for notes and session
ymh <ymh.work@gmail.com>
parents:
66
diff
changeset
|
43 |
|
|
3
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
44 |
}; |
|
3b5d37d84cfe
Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff
changeset
|
45 |
} |