53 lines
1.5 KiB
JavaScript
53 lines
1.5 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, options) => {
|
|
const models = Self.app.models;
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
const isEqualizated = Object.prototype.hasOwnProperty.call(data, 'isEqualizated');
|
|
if (isEqualizated) {
|
|
const client = await models.Client.findById(id, null, myOptions);
|
|
|
|
if (client) {
|
|
await models.Address.updateAll({clientFk: id}, data, myOptions);
|
|
await client.updateAttributes({hasToInvoiceByAddress: false}, myOptions);
|
|
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
};
|