39 lines
1.0 KiB
JavaScript
39 lines
1.0 KiB
JavaScript
|
module.exports = Self => {
|
||
|
Self.remoteMethod('updateTaxes', {
|
||
|
description: 'Updates the item taxes',
|
||
|
accessType: 'WRITE',
|
||
|
accepts: [{
|
||
|
arg: 'id',
|
||
|
type: 'number',
|
||
|
required: true,
|
||
|
description: 'The item id',
|
||
|
http: {source: 'path'}
|
||
|
}, {
|
||
|
arg: 'niches',
|
||
|
type: ['object'],
|
||
|
required: true,
|
||
|
description: 'The list of taxes to update',
|
||
|
http: {source: 'body'}
|
||
|
}],
|
||
|
returns: {
|
||
|
type: 'boolean',
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/:id/updateTaxes`,
|
||
|
verb: 'post'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.updateTaxes = async (id, taxes) => {
|
||
|
let promises = [];
|
||
|
for (let tax of taxes)
|
||
|
promises.push(Self.app.models.ItemTaxCountry.updateAll(
|
||
|
{id: tax.id},
|
||
|
{taxClassFk: tax.taxClassFk}
|
||
|
));
|
||
|
await Promise.all(promises);
|
||
|
return true;
|
||
|
};
|
||
|
};
|