implement mapping update

This commit is contained in:
Bilal Catic
2019-08-28 12:44:47 +02:00
parent 4999b1323f
commit 9878b5e6b4
6 changed files with 166 additions and 23 deletions

View File

@@ -70,13 +70,21 @@ const getResourceMappings = () => {
};
const getMappingsFromDatabase = () => {
return db.officeResourceMapping.findAll();
return db.officeResourceMapping.findAll({order: [['id']]});
};
const deleteMappingById = (id) => {
return db.officeResourceMapping.destroy({where: {id}});
};
const updateMappingById = (id, mapping) => {
if (mapping.id) {
delete mapping.id;
}
return db.officeResourceMapping.update(mapping, {where: {id}});
};
const saveNewMappingToDatabase = (mapping) => {
return db.officeResourceMapping.findOrCreate({where: {...mapping}, defaults: {...mapping}});
};
@@ -88,4 +96,5 @@ module.exports = {
getResourceMappings,
saveNewMappingToDatabase,
deleteMappingById,
updateMappingById,
};