salix/modules/ticket/back/methods/expedition/deleteExpeditions.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-10-07 08:47:54 +00:00
module.exports = Self => {
Self.remoteMethod('deleteExpeditions', {
description: 'Delete the selected expeditions',
accessType: 'WRITE',
accepts: [{
2022-10-18 09:47:37 +00:00
arg: 'expeditionIds',
2022-10-07 08:47:54 +00:00
type: ['number'],
required: true,
description: 'The expeditions ids to delete'
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/deleteExpeditions`,
verb: 'POST'
}
});
2022-10-18 09:47:37 +00:00
Self.deleteExpeditions = async(expeditionIds, options) => {
2022-10-07 08:47:54 +00:00
const models = Self.app.models;
const myOptions = {};
let tx;
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
const deletedExpeditions = await models.Expedition.destroyAll({
2022-10-18 09:47:37 +00:00
id: {inq: expeditionIds}
2022-10-07 08:47:54 +00:00
}, myOptions);
if (tx) await tx.commit();
return deletedExpeditions;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};