salix/modules/ticket/back/methods/sale-tracking/delete.js

56 lines
1.5 KiB
JavaScript

module.exports = Self => {
Self.remoteMethod('delete', {
description: 'Elimina el registro (si se cumple la condición) y inserta uno nuevo',
accessType: 'READ',
accepts: [
{
arg: 'saleFk',
type: 'number',
description: 'The sale id'
},
{
arg: 'stateCode',
type: 'string'
}
],
returns: {
type: ['object'],
root: true
},
http: {
path: `/delete`,
verb: 'POST'
}
});
Self.delete = async(saleFk, stateCode, options) => {
const models = Self.app.models;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
// const itemShelvingSales = await models.ItemShelvingSale.find({where: {saleFk: saleFk}}, myOptions);
// for (let itemShelvingSale of itemShelvingSales)
// await itemShelvingSale.destroy(myOptions);
// const filter = {
// where: {
// saleFk: saleFk,
// code: stateCode
// }
// };
// const saleTrackings = await models.SaleTracking.find(filter, myOptions);
// for (let saleTracking of saleTrackings)
// await saleTracking.destroy(myOptions);
query = `CALL vn.saleTracking_del(?, ?)`;
return Self.rawSql(query,
[
saleFk,
stateCode,
], myOptions);
};
};