#6276 createNewWarehouse methods migrated from silex to salix #1850
|
@ -3697,15 +3697,19 @@ UPDATE vn.collection
|
|||
UPDATE vn.sale
|
||||
SET isPicked =FALSE;
|
||||
|
||||
INSERT INTO machineWorkerConfig(maxHours)
|
||||
INSERT INTO vn.machineWorkerConfig(maxHours)
|
||||
VALUES(12);
|
||||
|
||||
INSERT INTO workerAppTester(workerFk) VALUES(66);
|
||||
INSERT INTO vn.workerAppTester(workerFk) VALUES(66);
|
||||
|
||||
INSERT INTO `vn`.`machine` (`plate`, `maker`, `model`, `warehouseFk`, `departmentFk`, `type`, `use`, `productionYear`, `workerFk`, `companyFk`)
|
||||
VALUES
|
||||
('RE-003', 'IRON', 'JPH-24', 60, 23, 'ELECTRIC TOW', 'Drag cars', 2020, 103, 442);
|
||||
|
||||
|
||||
INSERT INTO machineWorker(workerFk,machineFk,inTimed)
|
||||
VALUES (104,1,'2001-01-01 10:00:00.00.000');
|
||||
INSERT INTO vn.machineWorker(workerFk,machineFk,inTimed)
|
||||
VALUES (104,1,'2001-01-01 10:00:00.00.000');
|
||||
|
||||
UPDATE vn.buy
|
||||
SET itemOriginalFk = 1
|
||||
WHERE id = 1;
|
|
@ -0,0 +1,78 @@
|
|||
const {models} = require('vn-loopback/server/server');
|
||||
|
||||
fdescribe('saleTracking updateTracking()', () => {
|
||||
const saleFk = 1;
|
||||
const originalQuantity = 10;
|
||||
const code = 'PREPARED';
|
||||
const isChecked = true;
|
||||
const buyFk = 1;
|
||||
const isScanned = false;
|
||||
|
||||
beforeAll(async() => {
|
||||
ctx = {
|
||||
req: {
|
||||
accessToken: {userId: 104},
|
||||
headers: {origin: 'http://localhost'},
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
it('should add a new saleTracking and saleBuy', async() => {
|
||||
const tx = await models.SaleTracking.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
|
||||
try {
|
||||
const saleTrackingBefore = await models.SaleTracking.find(null, options);
|
||||
const saleBuyBefore = await models.SaleBuy.find(null, options);
|
||||
await models.SaleTracking.updateTracking(
|
||||
ctx,
|
||||
saleFk,
|
||||
originalQuantity,
|
||||
code,
|
||||
isChecked,
|
||||
buyFk,
|
||||
isScanned,
|
||||
options
|
||||
);
|
||||
|
||||
const saleTrackingAfter = await models.SaleTracking.find(null, options);
|
||||
const saleBuyAfter = await models.SaleBuy.find(null, options);
|
||||
|
||||
expect(saleTrackingAfter.length).toEqual(saleTrackingBefore.length + 1);
|
||||
expect(saleBuyAfter.length).toEqual(saleBuyBefore.length + 1);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
|
||||
it('should only update a saleTracking', async() => {
|
||||
const tx = await models.SaleTracking.beginTransaction({});
|
||||
const options = {transaction: tx};
|
||||
const saleFk = 2;
|
||||
|
||||
try {
|
||||
const saleTrackingBefore = await models.SaleTracking.find(null, options);
|
||||
await models.SaleTracking.updateTracking(
|
||||
ctx,
|
||||
saleFk,
|
||||
originalQuantity,
|
||||
code,
|
||||
isChecked,
|
||||
buyFk,
|
||||
isScanned,
|
||||
options
|
||||
);
|
||||
const saleTrackingAfter = await models.SaleTracking.find(null, options);
|
||||
|
||||
expect(saleTrackingAfter.length).toEqual(saleTrackingBefore.length + 1);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -39,7 +39,7 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.updateTracking = async(ctx, saleFk, originalQuantity, code, isChecked, buyFk, isScanned, options) => {
|
||||
Self.updateTracking = async(ctx, saleFk, originalQuantity, code, isChecked, buyFk, isScanned = null, options) => {
|
||||
const userId = ctx.req.accessToken.userId;
|
||||
const models = Self.app.models;
|
||||
const myOptions = {};
|
||||
|
@ -58,24 +58,31 @@ module.exports = Self => {
|
|||
where: {code},
|
||||
}, myOptions);
|
||||
|
||||
const attributes = {
|
||||
const uniqueAttributes = {
|
||||
saleFk,
|
||||
workerFk: userId,
|
||||
jorgep marked this conversation as resolved
Outdated
|
||||
stateFk: state?.id,
|
||||
};
|
||||
const attributes = {
|
||||
isChecked,
|
||||
originalQuantity,
|
||||
workerFk: userId,
|
||||
stateFk: state.id,
|
||||
isScanned: isScanned === undefined ? null : isScanned,
|
||||
isScanned
|
||||
};
|
||||
|
||||
const saleTracking = await models.SaleTracking.findOne({
|
||||
jorgep marked this conversation as resolved
Outdated
alexm
commented
Tambien se puede hacer 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
jorgep
commented
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í.
|
||||
where: attributes,
|
||||
where: uniqueAttributes,
|
||||
}, myOptions);
|
||||
|
||||
if (!saleTracking)
|
||||
await models.SaleTracking.create(attributes, myOptions);
|
||||
|
||||
else
|
||||
await saleTracking.updateAttributes(attributes, myOptions);
|
||||
if (!saleTracking) {
|
||||
await models.SaleTracking.create({
|
||||
...uniqueAttributes,
|
||||
...attributes
|
||||
}, myOptions);
|
||||
} else {
|
||||
await saleTracking.updateAttributes({
|
||||
...attributes
|
||||
}, myOptions);
|
||||
}
|
||||
|
||||
let isBuy;
|
||||
if (buyFk) {
|
||||
|
|
|
@ -17,9 +17,6 @@
|
|||
},
|
||||
"created": {
|
||||
"type": "date"
|
||||
},
|
||||
"isChecked": {
|
||||
"type": "number"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
@ -27,6 +24,11 @@
|
|||
"type": "belongsTo",
|
||||
"model": "Sale",
|
||||
"foreignKey": "saleFk"
|
||||
},
|
||||
"worker": {
|
||||
"type": "belongsTo",
|
||||
"model": "Worker",
|
||||
"foreignKey": "workerFk"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
No hace falta usar $t, UserError traduce por defecto.