#6276 createNewWarehouse methods migrated from silex to salix #1850

Merged
jorgep merged 158 commits from 6276-createNewWarehouse into dev 2024-03-06 11:32:11 +00:00
6 changed files with 142 additions and 1 deletions
Showing only changes of commit 8acd03f115 - Show all commits

View File

@ -5,4 +5,5 @@ INSERT INTO `salix`.`ACL` (model, property, accessType, permission, principalTyp
('MachineWorker','updateInTime','WRITE','ALLOW','ROLE','employee'),
('MachineWorker','add','READ','ALLOW','ROLE','employee'),
('MobileAppVersionControl','getVersion','READ','ALLOW','ROLE','employee'),
('SaleTracking','deleteTracking','WRITE','ALLOW','ROLE','employee');
('SaleTracking','deleteTracking','WRITE','ALLOW','ROLE','employee'),
('SaleTracking','updateTracking','WRITE','ALLOW','ROLE','employee');

View File

@ -0,0 +1,100 @@
module.exports = Self => {
Self.remoteMethodCtx('updateTracking', {
description: 'Modify a saleTracking record and, if applicable, add a corresponding record in saleBuy.',
accessType: 'WRITE',
accepts: [
{
arg: 'saleFk',
type: 'number',
required: true
},
{
arg: 'originalQuantity',
type: 'number',
required: true
},
{
arg: 'code',
type: 'string',
required: true
},
{
arg: 'isChecked',
type: 'number',
required: true
},
{
arg: 'buyFk',
type: 'number',
required: true
},
{
arg: 'isScanned',
type: 'number',
},
],
http: {
path: `/updateTracking`,
verb: 'POST'
}
});
Self.updateTracking = async(ctx, saleFk, originalQuantity, code, isChecked, buyFk, isScanned, options) => {
const userId = ctx.req.accessToken.userId;
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 state = await models.State.findOne({
where: {code},
}, myOptions);
const attributes = {
saleFk,
isChecked,
jorgep marked this conversation as resolved Outdated
Outdated
Review

No hace falta usar $t, UserError traduce por defecto.

No hace falta usar $t, UserError traduce por defecto.
originalQuantity,
workerFk: userId,
stateFk: state.id,
isScanned,
};
const saleTracking = await models.SaleTracking.findOne({
where: attributes,
}, myOptions);
jorgep marked this conversation as resolved Outdated
Outdated
Review

Tambien se puede hacer isScanned: !!isScanned y te ahorras el valor por defecto.
Pero no creo que haya una preferencia de hacerlo de una manera o de otra

Tambien se puede hacer `isScanned: !!isScanned` y te ahorras el valor por defecto. Pero no creo que haya una preferencia de hacerlo de una manera o de otra

En la tabla saleTracking -> el valor por defecto is NULL, no es solo true o false. Lo comenté con @sergiodt y quedamos así.

En la tabla saleTracking -> el valor por defecto is NULL, no es solo true o false. Lo comenté con @sergiodt y quedamos así.
if (!saleTracking)
await models.SaleTracking.create(attributes, myOptions);
else
await saleTracking.updateAttributes(attributes, myOptions);
let isBuy;
if (buyFk) {
isBuy = await models.Buy.findOne({
where: {
id: buyFk,
itemOriginalFk: {
neq: null
}
}
});
}
if (isBuy)
await models.SaleBuy.create({saleFk, buyFk}, myOptions);
if (tx) await tx.commit();
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};

View File

@ -65,6 +65,9 @@
"SaleTracking": {
"dataSource": "vn"
},
"SaleBuy": {
"dataSource": "vn"
},
"State": {
"dataSource": "vn"
},

View File

@ -0,0 +1,33 @@
{
"name": "SaleBuy",
"base": "VnModel",
"options": {
"mysql": {
"table": "saleBuy"
}
},
"properties": {
"saleFk": {
"id": true,
"type": "number",
"forceId": false
jorgep marked this conversation as resolved
Review

esto en que caso es necesario?

esto en que caso es necesario?
Review

@jgallego es necesario en 2 backs de saleTracking: mark y updateTracking. Lo dejo? O prefieres un rawSql?

@jgallego es necesario en 2 backs de saleTracking: mark y updateTracking. Lo dejo? O prefieres un rawSql?
Review

me refiero al parametro "forceId": false

me refiero al parametro "forceId": false
Review

Lo quito, creo que lo puse al principio se me olvido poner id: true

Lo quito, creo que lo puse al principio se me olvido poner id: true
},
"buyFk": {
"type": "number"
},
"created": {
"type": "date"
},
"isChecked": {
"type": "number"
}
},
"relations": {
"sale": {
"type": "belongsTo",
"model": "Sale",
"foreignKey": "saleFk"
}
}
}

View File

@ -3,4 +3,5 @@ module.exports = Self => {
require('../methods/sale-tracking/listSaleTracking')(Self);
require('../methods/sale-tracking/new')(Self);
require('../methods/sale-tracking/delete')(Self);
require('../methods/sale-tracking/updateTracking')(Self);
};

View File

@ -26,6 +26,9 @@
},
"originalQuantity": {
"type": "number"
},
"isScanned": {
"type": "number"
}
},
"relations": {