refs #5561 feat: utilizar métodos bd
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2023-06-02 13:31:41 +02:00
parent ba64dbbe46
commit 67413360c6
4 changed files with 42 additions and 36 deletions

View File

@ -0,0 +1,38 @@
DELIMITER $$
$$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`saleTracking_new`(
vSaleFK INT,
vIsChecked BOOLEAN,
vOriginalQuantity INT,
vWorkerFk INT,
vState VARCHAR(50),
vIsScanned BOOLEAN)
BEGIN
/**
* Modifica registro de saleTracking
*
* @param vSaleFK Identificador del registro a modificar
* @param vIsChecked Indica si la línea ha sido pulsada
* @param vOriginalQuantity Cantidad original
* @param vWorkerFk Identificador del trabajador
* @param vAction Identificador de la acción realizada
* @param vState Identificador del estado a modificar
* @param vIsScanned Identificador si se ha escaneado automáticamente o manual
*/
REPLACE vn.saleTracking(saleFk,
isChecked,
originalQuantity,
workerFk,
stateFk,
isScanned)
SELECT vSaleFK,
vIsChecked,
vOriginalQuantity,
IFNULL(vWorkerFk, vn.getUser()),
s.id,
vIsScanned
FROM vn.state s
WHERE s.code = vState COLLATE utf8_unicode_ci;
END$$
DELIMITER ;

View File

@ -25,26 +25,11 @@ module.exports = Self => {
});
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,
[

View File

@ -1,6 +1,6 @@
module.exports = Self => {
Self.remoteMethodCtx('replace', {
Self.remoteMethodCtx('new', {
description: 'Remplaza el registro o lo crea si no existe',
accessType: 'READ',
accepts: [
@ -27,34 +27,18 @@ module.exports = Self => {
root: true
},
http: {
path: `/replace`,
path: `/new`,
verb: 'POST'
}
});
Self.replace = async(ctx, saleFk, isChecked, quantity, stateCode, options) => {
const models = Self.app.models;
Self.new = async(ctx, saleFk, isChecked, quantity, stateCode, options) => {
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,
[
@ -62,7 +46,6 @@ module.exports = Self => {
isChecked,
quantity,
userId,
'parameterToDelete',
stateCode,
null
], myOptions);

View File

@ -1,6 +1,6 @@
module.exports = Self => {
require('../methods/sale-tracking/filter')(Self);
require('../methods/sale-tracking/listSaleTracking')(Self);
require('../methods/sale-tracking/replace')(Self);
require('../methods/sale-tracking/new')(Self);
require('../methods/sale-tracking/delete')(Self);
};