client/src/actions/notesActions.js
author ymh <ymh.work@gmail.com>
Fri, 23 Jun 2017 17:58:21 +0200
changeset 83 76a4e4b11762
parent 80 b3a02ea6d097
child 86 fa8ef84a1780
permissions -rw-r--r--
add server request for note update and delete
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
4a8bbd314a46 Store note JSON data.
Alexandre Segura <mex.zktk@gmail.com>
parents: 12
diff changeset
     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,
78
49c5ea36d0a4 Store margin comment.
Alexandre Segura <mex.zktk@gmail.com>
parents: 74
diff changeset
    16
    marginComment: data.marginComment,
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
    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
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
  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
    20
    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
    21
    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
    22
    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
    23
    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
    24
    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
    25
    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
    26
    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
    27
    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
    28
  }
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
    29
3
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
  return {
62
b2514a9bcd49 migrate to redux-offline + various optimisation
ymh <ymh.work@gmail.com>
parents: 59
diff changeset
    31
    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
    32
    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
    33
    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
    34
      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
    35
        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
    36
          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
    37
          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
    38
          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
    39
        },
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
        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
    41
        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
    42
      }
3
3b5d37d84cfe Some code rename and reorg + basic tests
ymh <ymh.work@gmail.com>
parents:
diff changeset
    43
    }
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
}
79
772b73e31069 Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents: 78
diff changeset
    46
772b73e31069 Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents: 78
diff changeset
    47
export const deleteNote = (note) => {
772b73e31069 Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents: 78
diff changeset
    48
  return {
772b73e31069 Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents: 78
diff changeset
    49
    type: types.DELETE_NOTE,
83
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    50
    note,
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    51
    meta: {
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    52
      offline: {
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    53
        effect: {
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    54
          url: `/api/notes/sessions/${note.get('session')}/notes/${note.get('_id')}/`,
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    55
          method: 'DELETE'
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    56
        },
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    57
        commit: { type: types.NOOP },
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    58
        rollback: { type: types.NOOP }
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    59
      }
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    60
    }
79
772b73e31069 Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents: 78
diff changeset
    61
  };
772b73e31069 Introduce note editing, allow deleting note.
Alexandre Segura <mex.zktk@gmail.com>
parents: 78
diff changeset
    62
}
80
b3a02ea6d097 Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents: 79
diff changeset
    63
b3a02ea6d097 Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents: 79
diff changeset
    64
export const updateNote = (note, data) => {
83
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    65
  const noteSrvr = {
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    66
    raw: JSON.stringify(data.raw),
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    67
    plain: data.plain,
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    68
    html: data.html,
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    69
    categorization: JSON.stringify(data.categories),
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    70
  }
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    71
80
b3a02ea6d097 Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents: 79
diff changeset
    72
  return {
b3a02ea6d097 Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents: 79
diff changeset
    73
    type: types.UPDATE_NOTE,
b3a02ea6d097 Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents: 79
diff changeset
    74
    note,
83
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    75
    data,
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    76
    meta: {
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    77
      offline: {
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    78
        effect: {
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    79
          url: `/api/notes/sessions/${note.get('session')}/notes/${note.get('_id')}/`,
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    80
          method: 'PUT',
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    81
          data: noteSrvr
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    82
        },
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    83
        commit: { type: types.NOOP },
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    84
        rollback: { type: types.NOOP }
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    85
      }
76a4e4b11762 add server request for note update and delete
ymh <ymh.work@gmail.com>
parents: 80
diff changeset
    86
    }
80
b3a02ea6d097 Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents: 79
diff changeset
    87
  };
b3a02ea6d097 Implement note edition.
Alexandre Segura <mex.zktk@gmail.com>
parents: 79
diff changeset
    88
}