client/src/sagas/SessionSyncronizer.js
changeset 129 d48946d164c6
child 132 906a6c7c7943
equal deleted inserted replaced
128:34a75bd8d0b9 129:d48946d164c6
       
     1 import { select } from 'redux-saga/effects'
       
     2 import { getCreatedSessions, getUpdatedSessions, getDeletedSessions } from './selectors';
       
     3 import { ActionEnum } from '../constants';
       
     4 import moment from 'moment';
       
     5 import SessionRecord from '../store/sessionRecord';
       
     6 import { doDeleteSession, loadSession, resetActionSession } from '../actions/sessionsActions';
       
     7 import Immutable from 'immutable';
       
     8 import SyncMixin from './BaseSyncronizer';
       
     9 
       
    10 class SessionSyncBase {
       
    11 
       
    12   // local diffs (immutable)
       
    13   * getLocalDiffs() {
       
    14     return Immutable.Map({
       
    15       created: yield select(getCreatedSessions),
       
    16       updated: yield select(getUpdatedSessions),
       
    17       deleted: yield select(getDeletedSessions)
       
    18     })
       
    19   }
       
    20 
       
    21   // remote urls
       
    22   getRemoteLoadUrl() {
       
    23     return "/api/notes/sessions/";
       
    24   }
       
    25 
       
    26   getRemoteDeleteUrl(localObjInst) {
       
    27     return `/api/notes/sessions/${localObjInst.get('_id')}/`;
       
    28   }
       
    29 
       
    30   getRemoteCreateUrl(localObjInst) {
       
    31     return "/api/notes/sessions/";
       
    32   }
       
    33 
       
    34   getRemoteUpdateUrl(localObjInst) {
       
    35     return `/api/notes/sessions/${localObjInst.get('_id')}/`;
       
    36   }
       
    37 
       
    38   // build remote json message
       
    39   getRemoteData(localObjInst) {
       
    40     return {
       
    41       ext_id: localObjInst.get('_id'),
       
    42       date: localObjInst.get('date'),
       
    43       title: localObjInst.get('title'),
       
    44       description: localObjInst.get('description'),
       
    45       protocol: ''
       
    46     };
       
    47   }
       
    48 
       
    49   getLocalRecord(remoteObj) {
       
    50     return new SessionRecord({
       
    51         _id: remoteObj.ext_id,
       
    52         title: remoteObj.title,
       
    53         description: remoteObj.description,
       
    54         date: moment(remoteObj.date).toDate(),
       
    55         action: ActionEnum.NONE,
       
    56         group: null
       
    57     });
       
    58   }
       
    59 
       
    60   // actions
       
    61   doDeleteLocalObj(localObjId) {
       
    62     return doDeleteSession(localObjId);
       
    63   }
       
    64 
       
    65   resetLocalObj(localObjInst) {
       
    66     return resetActionSession(localObjInst);
       
    67   }
       
    68 
       
    69   loadObj(objRecord) {
       
    70     return loadSession(objRecord);
       
    71   }
       
    72 
       
    73 }
       
    74 
       
    75 export class SessionSynchronizer extends SyncMixin(SessionSyncBase) {}
       
    76 
       
    77 export default SessionSynchronizer;