salix/modules/client/back/methods/client/addressesPropagateRe.js

44 lines
1.3 KiB
JavaScript

module.exports = function(Self) {
Self.remoteMethod('addressesPropagateRe', {
description: 'Change property isEqualizated in all client addresses',
accessType: 'WRITE',
accepts: [
{
arg: 'id',
type: 'string',
required: true,
description: 'Client id',
http: {source: 'path'}
},
{
arg: 'data',
type: 'Object',
required: true,
description: 'data with new value',
http: {source: 'body'}
}
],
returns: {
arg: 'data',
type: 'boolean',
root: true
},
http: {
path: `/:id/addressesPropagateRe`,
verb: 'patch'
}
});
Self.addressesPropagateRe = async(id, data) => {
if (data.hasOwnProperty('isEqualizated')) {
let client = await Self.app.models.Client.findById(id);
if (client) {
await Self.app.models.Address.updateAll({clientFk: id}, data);
await client.updateAttributes({hasToInvoiceByAddress: false});
return true;
}
}
return false;
};
};