2022-04-08 05:37:17 +00:00
|
|
|
|
|
|
|
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({});
|
2022-04-08 05:37:17 +00:00
|
|
|
const myOptions = {};
|
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
2022-04-12 10:44:46 +00:00
|
|
|
if (!myOptions.transaction)
|
2022-04-08 05:37:17 +00:00
|
|
|
myOptions.transaction = tx;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const models = Self.app.models;
|
2022-04-21 07:34:13 +00:00
|
|
|
const promises = [];
|
2022-04-08 05:37:17 +00:00
|
|
|
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-08 05:37:17 +00:00
|
|
|
}
|
|
|
|
|
2022-04-21 07:34:13 +00:00
|
|
|
const updatedSales = await Promise.all(promises);
|
|
|
|
|
2022-04-08 05:37:17 +00:00
|
|
|
if (tx) await tx.commit();
|
|
|
|
|
2022-04-21 07:34:13 +00:00
|
|
|
return updatedSales;
|
2022-04-08 05:37:17 +00:00
|
|
|
} catch (e) {
|
|
|
|
if (tx) await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|