#6964 _ itemOlder #2197
|
@ -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');
|
|
@ -350,4 +350,4 @@
|
|||
"The line could not be marked": "La linea no puede ser marcada",
|
||||
"This password can only be changed by the user themselves": "Esta contraseña solo puede ser modificada por el propio usuario",
|
||||
"They're not your subordinate": "No es tu subordinado/a."
|
||||
}
|
||||
}
|
|
@ -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
|
||||
description: 'Item id'
|
||||
}],
|
||||
returns: {
|
||||
type: 'boolean',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/hasItemOlder`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
sergiodt marked this conversation as resolved
Outdated
alexm
commented
Els 3(parking, shelvingFkOut, itemFk) poden ser null a la vega? O faria falta al menys uno? 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(...)
sergiodt
commented
Posat Posat
|
||||
Self.hasItemOlder = async(shelvingFkIn, parking, shelvingFkOut, itemFk, options) => {
|
||||
sergiodt marked this conversation as resolved
alexm
commented
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
carlosap
commented
Millor fiquem un alias al cam Millor fiquem un alias al cam
alexm
commented
Faltaria la traduccion Faltaria la traduccion
sergiodt
commented
Afegida Afegida
|
||||
|
||||
sergiodt marked this conversation as resolved
Outdated
carlosap
commented
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
carlosap
commented
Tabulació Tabulació
|
||||
SELECT ish.itemFk, created,shelvingFk
|
||||
sergiodt marked this conversation as resolved
Outdated
carlosap
commented
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??
sergiodt
commented
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
alexm
commented
falta gastar la transaccio (...shelvingFkOut, itemFk, itemFk], options) falta gastar la transaccio (...shelvingFkOut, itemFk, itemFk], options)
sergiodt
commented
Llevat options Llevat options
alexm
commented
Es ficarlo sino no gastarà la transaccio Es ficarlo sino no gastarà la transaccio
sergiodt
commented
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
alexm
commented
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
alexm
commented
Aci Aci
alexm
commented
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;
|
||||
};
|
||||
};
|
|
@ -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
alexm
commented
Al cridar a la funcio hi ha que seguir el mateix ordre que dalt ( Per tant seria 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
alexm
commented
, myOptions , myOptions
|
||||
}, myOptions);
|
||||
sergiodt marked this conversation as resolved
Outdated
alexm
commented
, myOptions , myOptions
|
||||
const result = await models.ItemShelving.hasItemOlder(shelvingFkIn, parking, null, null, myOptions);
|
||||
sergiodt marked this conversation as resolved
Outdated
alexm
commented
Aci deuries gastar la transaccio Aci deuries gastar la transaccio
await models.ItemShelving.hasItemOlder(shelvingFkIn, parking, null, null, myOptions)
sergiodt
commented
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;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -4,4 +4,5 @@ module.exports = Self => {
|
|||
require('../methods/item-shelving/getInventory')(Self);
|
||||
require('../methods/item-shelving/getAlternative')(Self);
|
||||
require('../methods/item-shelving/updateFromSale')(Self);
|
||||
require('../methods/item-shelving/hasItemOlder')(Self);
|
||||
};
|
||||
|
|
He buscat y type int no ho hem gastat mai,
Seria
type: 'integer',
vaig mesclant llenguatges :-)