2018-01-29 11:37:54 +00:00
|
|
|
module.exports = function(Client) {
|
|
|
|
Client.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'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-07-03 09:13:33 +00:00
|
|
|
Client.addressesPropagateRe = async (id, data) => {
|
2018-01-29 11:37:54 +00:00
|
|
|
if (data.hasOwnProperty('isEqualizated')) {
|
2018-07-03 09:13:33 +00:00
|
|
|
await Client.app.models.Address.updateAll({clientFk: id}, data);
|
|
|
|
await Client.update({id: id}, {hasToInvoiceByAddress: false});
|
|
|
|
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
|
|
|
};
|