salix/services/client/common/methods/address/crudAddressObservations.js

38 lines
1.1 KiB
JavaScript

module.exports = Self => {
Self.remoteMethod('crudAddressObservations', {
description: 'create, delete or update address observations',
accessType: 'WRITE',
accepts: [
{
arg: 'observations',
type: 'Object',
require: true,
description: 'object with observations to create, delete or update, Example: {delete: [], create: [], update: []}',
http: {source: 'body'}
}
],
http: {
path: `/crudAddressObservations`,
verb: 'post'
}
});
Self.crudAddressObservations = observations => {
let promises = [];
if (observations.delete.length) {
promises.push(Self.destroyAll({id: {inq: observations.delete}}));
}
if (observations.create.length) {
promises.push(Self.create(observations.create));
}
if (observations.update.length) {
observations.update.forEach(observation => {
promises.push(Self.upsert(observation));
});
}
return Promise.all(promises);
};
};