49 lines
1.2 KiB
JavaScript
49 lines
1.2 KiB
JavaScript
|
|
||
|
module.exports = Self => {
|
||
|
Self.remoteMethod('deleteExpeditions', {
|
||
|
description: 'Delete the selected expeditions',
|
||
|
accessType: 'WRITE',
|
||
|
accepts: [{
|
||
|
arg: 'expeditionsIds',
|
||
|
type: ['number'],
|
||
|
required: true,
|
||
|
description: 'The expeditions ids to delete'
|
||
|
}],
|
||
|
returns: {
|
||
|
type: ['object'],
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/deleteExpeditions`,
|
||
|
verb: 'POST'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.deleteExpeditions = async(expeditionsIds, options) => {
|
||
|
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({
|
||
|
id: {inq: expeditionsIds}
|
||
|
}, myOptions);
|
||
|
|
||
|
if (tx) await tx.commit();
|
||
|
|
||
|
return deletedExpeditions;
|
||
|
} catch (e) {
|
||
|
if (tx) await tx.rollback();
|
||
|
throw e;
|
||
|
}
|
||
|
};
|
||
|
};
|