2018-10-03 09:27:55 +00:00
|
|
|
module.exports = function(Self) {
|
|
|
|
Self.remoteMethod('addressesPropagateRe', {
|
2018-01-29 11:37:54 +00:00
|
|
|
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'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-10-03 09:27:55 +00:00
|
|
|
Self.addressesPropagateRe = async (id, data) => {
|
2018-01-29 11:37:54 +00:00
|
|
|
if (data.hasOwnProperty('isEqualizated')) {
|
2018-10-03 09:27:55 +00:00
|
|
|
await Self.app.models.Address.updateAll({clientFk: id}, data);
|
|
|
|
let client = await Self.app.models.Client.findById(id)
|
|
|
|
await client.updateAttributes({hasToInvoiceByAddress: false});
|
2018-07-03 09:13:33 +00:00
|
|
|
return true;
|
2018-01-29 11:37:54 +00:00
|
|
|
}
|
2018-07-03 09:13:33 +00:00
|
|
|
return false;
|
2018-01-29 11:37:54 +00:00
|
|
|
};
|
2018-03-02 12:46:25 +00:00
|
|
|
};
|