ldc-com-app/ComApp/src/App/Store/Reducers/contacts.js
Jérémy Munsch 918e20a72b
SYNC 15 Major update, Formularies and Fixes
- Add type Definitions
- Fix models methods
- Sync controller add route names
- Formularies sync OK
- Closes https://lab.s-web.fr/ldc-web/projets/com-app-bo/-/issues/18
- Closes https://lab.s-web.fr/ldc-web/projets/com-app/-/issues/9
2023-09-04 10:08:53 +02:00

38 lines
1.1 KiB
JavaScript

import {
DELETE_CONTACT,
INIT_CONTACT,
SET_CONTACT,
} from '../Actions/actionType';
// Models
import { Contact } from '../../../Database';
/** @type {import('../../Models/Contact').Contact[]} */
const initialState = [];
/**
* @param {typeof initialState} state
* @param {import('../Actions/contacts').InitContactAction|import('../Actions/contacts').SetContactAction|import('../Actions/contacts').DeleteContactAction} action
* @returns {import('realm').Results<import('../../Models/Contact').Contact>}
*/
const reducer = (state = initialState, action) => {
switch (action.type) {
case INIT_CONTACT: {
return Contact.getAllEditable(action.currentUser.id);
}
case SET_CONTACT: {
action.data.app_user_id = action.currentUser.id;
Contact.set(action.data);
return Contact.getAllEditable(action.currentUser.id);
}
case DELETE_CONTACT: {
Contact.delete(action.currentUser.id, action.uuid);
return Contact.getAllEditable(action.currentUser.id);
}
default: {
return state;
}
}
};
export default reducer;