salix/modules/claim/back/methods/claim/updateClaimDestination.js

56 lines
1.6 KiB
JavaScript
Raw Normal View History

module.exports = Self => {
Self.remoteMethod('updateClaimDestination', {
description: 'Update a claim with privileges',
accessType: 'WRITE',
accepts: [{
arg: 'rows',
type: ['object'],
required: true,
description: `the sales which will be modified the claimDestinationFk`
}, {
arg: 'claimDestinationFk',
type: 'number',
required: true
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/updateClaimDestination`,
verb: 'post'
}
});
Self.updateClaimDestination = async(rows, claimDestinationFk, options) => {
2022-04-12 10:44:46 +00:00
const tx = await Self.beginTransaction({});
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
2022-04-12 10:44:46 +00:00
if (!myOptions.transaction)
myOptions.transaction = tx;
try {
const models = Self.app.models;
2022-04-21 07:34:13 +00:00
const promises = [];
for (let row of rows) {
const claimEnd = await models.ClaimEnd.findById(row.id, null, myOptions);
2022-04-21 07:34:13 +00:00
const updatedClaimEnd = claimEnd.updateAttribute('claimDestinationFk', claimDestinationFk, myOptions);
promises.push(updatedClaimEnd);
}
2022-04-21 07:34:13 +00:00
const updatedSales = await Promise.all(promises);
if (tx) await tx.commit();
2022-04-21 07:34:13 +00:00
return updatedSales;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};