#6964 _ itemOlder #2197

Merged
sergiodt merged 26 commits from 6964_itemOlder into dev 2024-04-04 14:18:20 +00:00
5 changed files with 114 additions and 1 deletions

View File

@ -0,0 +1,4 @@
-- Place your SQL code here
INSERT INTO salix.ACL (model, property, accessType, permission, principalType, principalId)
VALUES('ItemShelving', 'hasItemOlder', 'READ', 'ALLOW', 'ROLE', 'production');

View File

@ -0,0 +1,63 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethod('hasItemOlder', {
description:
'Get boolean if any or specific item of the shelving has older created in another shelving or parking',
accessType: 'READ',
accepts: [{
arg: 'shelvingFkIn',
type: 'string',
required: true,
description: 'Shelving code'
},
{
arg: 'parking',
type: 'string',
description: 'Parking code'
},
{
arg: 'shelvingFkOut',
type: 'string',
description: 'Shelving code'
},
{
arg: 'itemFk',
type: 'integer',
sergiodt marked this conversation as resolved Outdated
Outdated
Review

He buscat y type int no ho hem gastat mai,
Seria type: 'integer',

He buscat y type int no ho hem gastat mai, Seria `type: 'integer',`

vaig mesclant llenguatges :-)

vaig mesclant llenguatges :-)
description: 'Item id'
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/hasItemOlder`,
verb: 'GET'
}
});
sergiodt marked this conversation as resolved Outdated
Outdated
Review

Els 3(parking, shelvingFkOut, itemFk) poden ser null a la vega? O faria falta al menys uno?
Per si fera falta ficar un if(!parking && !shelvingFkOut && !itemFk) return throw new UserError(...)

Els 3(parking, shelvingFkOut, itemFk) poden ser null a la vega? O faria falta al menys uno? Per si fera falta ficar un if(!parking && !shelvingFkOut && !itemFk) return throw new UserError(...)

Posat

Posat
Self.hasItemOlder = async(shelvingFkIn, parking, shelvingFkOut, itemFk, options) => {
sergiodt marked this conversation as resolved
Review
    const myOptions = {};

    if (typeof options == 'object')
        Object.assign(myOptions, options);
const myOptions = {}; if (typeof options == 'object') Object.assign(myOptions, options);
if (!parking && !shelvingFkOut) throw new UserError('Missing data: parking or shelving');
sergiodt marked this conversation as resolved Outdated

Millor fiquem un alias al cam

Millor fiquem un alias al cam
Review

Faltaria la traduccion

Faltaria la traduccion
Review

Afegida

Afegida
sergiodt marked this conversation as resolved Outdated

Tabulació

Tabulació
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const result = await Self.rawSql(`
SELECT COUNT(ish.id) countItemOlder
FROM vn.itemShelving ish
JOIN (
sergiodt marked this conversation as resolved Outdated

Tabulació

Tabulació
SELECT ish.itemFk, created,shelvingFk
sergiodt marked this conversation as resolved Outdated

en la subconsulta el p.code y el LEFT JOIN vn.parking p ON p.id = s.parkingFk sirven para algo??

en la subconsulta el p.code y el LEFT JOIN vn.parking p ON p.id = s.parkingFk sirven para algo??

Llevat

Llevat
FROM vn.itemShelving ish
JOIN vn.shelving s ON ish.shelvingFk = s.code
WHERE ish.shelvingFk = ?
)sub ON sub.itemFK = ish.itemFk
JOIN vn.shelving s ON s.code = ish.shelvingFk
sergiodt marked this conversation as resolved Outdated
Outdated
Review

falta gastar la transaccio (...shelvingFkOut, itemFk, itemFk], options)

falta gastar la transaccio (...shelvingFkOut, itemFk, itemFk], options)

Llevat options

Llevat options
Outdated
Review

Es ficarlo sino no gastarà la transaccio

Es ficarlo sino no gastarà la transaccio

L'he posat però no veia que fera falta...

L'he posat però no veia que fera falta...
JOIN vn.parking p ON p.id = s.parkingFk
sergiodt marked this conversation as resolved Outdated
Outdated
Review

Si li poses el alias aci hi ha que canviarlo

Si li poses el alias aci hi ha que canviarlo
WHERE sub.created > ish.created
sergiodt marked this conversation as resolved Outdated
Outdated
Review

Aci

Aci
Outdated
Review

myOptions

myOptions
AND (p.code <> ? OR ? IS NULL)
AND (ish.shelvingFk <> ? OR ? IS NULL)
AND (ish.itemFk <> ? OR ? IS NULL)`,
[shelvingFkIn, parking, parking, shelvingFkOut, shelvingFkOut, itemFk, itemFk], myOptions);
return result[0]['countItemOlder'] > 0;
};
};

View File

@ -0,0 +1,45 @@
const {models} = require('vn-loopback/server/server');
describe('itemShelving hasOlder()', () => {
it('should return false because there are not older items', async() => {
const shelvingFkIn = 'GVC';
const shelvingFkOut = 'HEJ';
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, null, shelvingFkOut);
sergiodt marked this conversation as resolved Outdated
Outdated
Review

Al cridar a la funcio hi ha que seguir el mateix ordre que dalt (async(shelvingFkIn, parking, shelvingFkOut, itemFk, options)

Per tant seria await models.ItemShelving.hasItemOlder(shelvingFkIn, null, shelvingFkOut)

Al cridar a la funcio hi ha que seguir el mateix ordre que dalt (`async(shelvingFkIn, parking, shelvingFkOut, itemFk, options`) Per tant seria `await models.ItemShelving.hasItemOlder(shelvingFkIn, null, shelvingFkOut)`
expect(result).toBe(false);
});
it('should return false because there are not older items in parking', async() => {
const shelvingFkIn = 'HEJ';
const parking = '700-01';
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking);
expect(result).toBe(false);
});
it('should return true because there is an older item', async() => {
const shelvingFkIn = 'UXN';
const shelvingFkOut = 'PCC';
const parking = 'A-01-1';
const itemFk = 1;
const tx = await models.ItemShelving.beginTransaction({});
const myOptions = {transaction: tx};
const filter = {where: {shelvingFk: shelvingFkOut}
};
try {
const itemShelvingBefore = await models.ItemShelving.findOne(filter, myOptions);
await itemShelvingBefore.updateAttributes({
itemFk: itemFk
sergiodt marked this conversation as resolved
Review

, myOptions

, myOptions
}, myOptions);
sergiodt marked this conversation as resolved Outdated
Outdated
Review

, myOptions

, myOptions
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking, null, null, myOptions);
sergiodt marked this conversation as resolved Outdated
Outdated
Review

Aci deuries gastar la transaccio
await models.ItemShelving.hasItemOlder(shelvingFkIn, parking, null, null, myOptions)

Aci deuries gastar la transaccio await models.ItemShelving.hasItemOlder(shelvingFkIn, parking, null, null, myOptions)

Ací si que veig que faltava posar myOptions perquè faig més accions

Ací si que veig que faltava posar myOptions perquè faig més accions
expect(result).toBe(true);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
});

View File

@ -4,4 +4,5 @@ module.exports = Self => {
require('../methods/item-shelving/getInventory')(Self); require('../methods/item-shelving/getInventory')(Self);
require('../methods/item-shelving/getAlternative')(Self); require('../methods/item-shelving/getAlternative')(Self);
require('../methods/item-shelving/updateFromSale')(Self); require('../methods/item-shelving/updateFromSale')(Self);
require('../methods/item-shelving/hasItemOlder')(Self);
}; };