#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
7 changed files with 26 additions and 16 deletions
Showing only changes of commit 21cf05ddd0 - Show all commits

View File

@ -1,6 +1,6 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
fdescribe('itemShelving return()', () => { describe('itemShelving return()', () => {
beforeAll(async() => { beforeAll(async() => {
ctx = { ctx = {
req: { req: {

View File

@ -24,12 +24,17 @@ module.exports = Self => {
}, },
}); });
Self.card = async(itemFk, warehouseFk) => { Self.card = async(itemFk, warehouseFk, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const models = Self.app.models; const models = Self.app.models;
const [[itemInfo]] = await Self.rawSql('CALL vn.item_getInfo(?, ?)', [itemFk, warehouseFk]); const [[itemInfo]] = await Self.rawSql('CALL vn.item_getInfo(?, ?)', [itemFk, warehouseFk], myOptions);
const barcodeItems = await Self.rawSql('SELECT vn.barcodeToItem(?) as realIdItem', [itemFk]); const barcodeItems = await Self.rawSql('SELECT vn.barcodeToItem(?) as realIdItem', [itemFk], myOptions);
jorgep marked this conversation as resolved Outdated

quitar esta llamada, dentro de item_getInfo ya se llama a barcodeToItem por tanto itemInfo ya contiene el id que se busca

quitar esta llamada, dentro de item_getInfo ya se llama a barcodeToItem por tanto itemInfo ya contiene el id que se busca

@sergiodt es correcto o quieres los barcodes tambien?

@sergiodt es correcto o quieres los barcodes tambien?
const [realIdItem] = barcodeItems.map(barcodeItem => barcodeItem.realIdItem); const [realIdItem] = barcodeItems.map(barcodeItem => barcodeItem.realIdItem);
jorgep marked this conversation as resolved Outdated

quitar salto

quitar salto
const barcodes = await models.ItemBarcode.find({ const barcodes = await models.ItemBarcode.find({

View File

@ -3,7 +3,7 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
fdescribe('sale model ', () => { describe('sale model ', () => {
const ctx = { const ctx = {
req: { req: {
accessToken: {userId: 9}, accessToken: {userId: 9},

View File

@ -79,7 +79,7 @@ describe('Travel extraCommunityFilter()', () => {
const result = await app.models.Travel.extraCommunityFilter(ctx, filter); const result = await app.models.Travel.extraCommunityFilter(ctx, filter);
expect(result.length).toEqual(9); expect(result.length).toEqual(8);
}); });
it('should return the travel matching "cargoSupplierFk"', async() => { it('should return the travel matching "cargoSupplierFk"', async() => {

View File

@ -80,6 +80,6 @@ describe('Travel filter()', () => {
const result = await app.models.Travel.filter(ctx); const result = await app.models.Travel.filter(ctx);
expect(result.length).toEqual(6); expect(result.length).toEqual(5);
}); });
}); });

View File

@ -15,7 +15,7 @@ module.exports = Self => {
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const isOperator = await Self.findById(user, myOptions); const isOperator = await Self.findById(userId, myOptions);
if (!isOperator) await Self.create({workerFk: userId}, myOptions); if (!isOperator) await Self.create({workerFk: userId}, myOptions);
jorgep marked this conversation as resolved Outdated

No sé si esto ya lo hablamos, me suena que sí, pero por asegurar.
Aquí habéis contemplado no crear este método y llamar al create nativo de loopback gestionando el error en caso de que ya exista?

No sé si esto ya lo hablamos, me suena que sí, pero por asegurar. Aquí habéis contemplado no crear este método y llamar al create nativo de loopback gestionando el error en caso de que ya exista?

@jgallego Sí, acabo de hablar con Sergio y hemos quedado en cambiarlo a como dices tú.

@jgallego Sí, acabo de hablar con Sergio y hemos quedado en cambiarlo a como dices tú.
}; };
}; };

View File

@ -1,8 +1,8 @@
const {models} = require('vn-loopback/server/server'); const {models} = require('vn-loopback/server/server');
describe('operator add()', () => { describe('operator add()', () => {
const itBoss = 104; const noOperator = 104;
const noWorker = 100000; const operator = 9;
beforeAll(async() => { beforeAll(async() => {
ctx = { ctx = {
@ -14,18 +14,23 @@ describe('operator add()', () => {
}; };
}); });
it('should throw an error if the worker does not exist', async() => { it('should not add an existent operator', async() => {
const tx = await models.Operator.beginTransaction({}); const tx = await models.Operator.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
ctx.req.accessToken.userId = noWorker; ctx.req.accessToken.userId = operator;
try { try {
const operatorBefore = await models.Operator.find(null, options);
const isOperator = await models.Operator.findOne(null, options);
expect(isOperator).toBeDefined();
await models.Operator.add(ctx, options); await models.Operator.add(ctx, options);
const operatorAfter = await models.Operator.find(null, options);
expect(operatorBefore.length).toEqual(operatorAfter.length);
await tx.rollback(); await tx.rollback();
} catch (e) { } catch (e) {
const error = e;
expect(error.message).toEqual('This worker does not exist');
await tx.rollback(); await tx.rollback();
} }
}); });
@ -33,7 +38,7 @@ describe('operator add()', () => {
it('should add a new operator successfully', async() => { it('should add a new operator successfully', async() => {
const tx = await models.Operator.beginTransaction({}); const tx = await models.Operator.beginTransaction({});
const options = {transaction: tx}; const options = {transaction: tx};
ctx.req.accessToken.userId = itBoss; ctx.req.accessToken.userId = noOperator;
try { try {
const operatorBefore = await models.Operator.find(null, options); const operatorBefore = await models.Operator.find(null, options);