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

71 lines
1.8 KiB
JavaScript

module.exports = Self => {
Self.remoteMethodCtx('replace', {
description: 'Remplaza el registro o lo crea si no existe',
accessType: 'READ',
accepts: [
{
arg: 'saleFk',
type: 'number',
description: 'The sale id'
},
{
arg: 'isChecked',
type: 'boolean'
},
{
arg: 'quantity',
type: 'number'
},
{
arg: 'stateCode',
type: 'string'
}
],
returns: {
type: ['object'],
root: true
},
http: {
path: `/replace`,
verb: 'POST'
}
});
Self.replace = async(ctx, saleFk, isChecked, quantity, stateCode, options) => {
const models = Self.app.models;
const myOptions = {};
const userId = ctx.req.accessToken.userId;
if (typeof options == 'object')
Object.assign(myOptions, options);
// const state = await models.State.findOne({
// where: {code: stateCode}
// }, myOptions);
// if (!state) return;
// const data = {
// saleFk: saleFk,
// isChecked: isChecked,
// originalQuantity: quantity,
// workerFk: userId,
// stateFk: state.id
// };
// return models.SaleTracking.replaceOrCreate(data, myOptions);
query = `CALL vn.saleTracking_new(?, ?, ?, ?, ?, ?, ?)`;
return Self.rawSql(query,
[
saleFk,
isChecked,
quantity,
userId,
'parameterToDelete',
stateCode,
null
], myOptions);
};
};