salix/modules/item/back/methods/item-shelving/deleteItemShelvings.js

57 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-10-11 06:40:22 +00:00
module.exports = Self => {
Self.remoteMethod('deleteItemShelvings', {
2022-10-26 07:30:17 +00:00
description: 'Deletes the selected item shelvings',
2022-10-11 06:40:22 +00:00
accessType: 'WRITE',
accepts: [{
arg: 'itemShelvingIds',
type: ['number'],
required: true,
description: 'The itemShelving ids to delete'
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/deleteItemShelvings`,
verb: 'POST'
}
});
Self.deleteItemShelvings = async(itemShelvingIds, 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 {
2022-10-26 07:30:17 +00:00
const promises = [];
for (let itemShelvingId of itemShelvingIds) {
2024-10-06 08:54:51 +00:00
const itemShelvingSaleToDelete = models.ItemShelvingSale.destroyAll({
itemShelvingFk: itemShelvingId
}, myOptions);
promises.push(itemShelvingSaleToDelete);
2022-10-26 07:30:17 +00:00
const itemShelvingToDelete = models.ItemShelving.destroyById(itemShelvingId, myOptions);
promises.push(itemShelvingToDelete);
}
const deletedItemShelvings = await Promise.all(promises);
2022-10-11 06:40:22 +00:00
if (tx) await tx.commit();
return deletedItemShelvings;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};