#6964 _ itemOlder #2197
|
@ -1,9 +1,10 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('hasItemOlder', {
|
||||
description: 'Get boolean if any item of the shelving has older created in another shelving ',
|
||||
description:
|
||||
'Get boolean if any or specific item of the shelving has older created in another shelving or parking',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'shelvingFk',
|
||||
arg: 'shelvingFkIn',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Shelving code'
|
||||
|
@ -11,8 +12,17 @@ module.exports = Self => {
|
|||
{
|
||||
arg: 'parking',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'Parking code'
|
||||
},
|
||||
{
|
||||
arg: 'shelvingFkOut',
|
||||
type: 'string',
|
||||
description: 'Shelving code'
|
||||
},
|
||||
{
|
||||
arg: 'itemFk',
|
||||
type: 'int',
|
||||
description: 'Item id'
|
||||
sergiodt marked this conversation as resolved
Outdated
|
||||
}],
|
||||
returns: {
|
||||
type: 'boolean',
|
||||
|
@ -24,21 +34,24 @@ module.exports = Self => {
|
|||
}
|
||||
});
|
||||
|
||||
Self.hasItemOlder = async(shelvingFk, parking, options) => {
|
||||
Self.hasItemOlder = async(shelvingFkIn, parking, shelvingFkOut, itemFk, options) => {
|
||||
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
|
||||
const result = await Self.rawSql(`
|
||||
sergiodt marked this conversation as resolved
alexm
commented
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
|
||||
SELECT COUNT(ish.id)
|
||||
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
|
||||
FROM vn.itemShelving ish
|
||||
JOIN (
|
||||
SELECT ish.itemFk, created,shelvingFk, p.code
|
||||
FROM vn.itemShelving ish
|
||||
JOIN vn.shelving s ON ish.shelvingFk = s.code
|
||||
JOIN vn.parking p ON p.id = s.parkingFk
|
||||
FROM vn.itemShelving ish
|
||||
sergiodt marked this conversation as resolved
Outdated
carlosap
commented
Tabulació Tabulació
|
||||
JOIN (
|
||||
SELECT ish.itemFk, created,shelvingFk, p.code
|
||||
FROM vn.itemShelving ish
|
||||
JOIN vn.shelving s ON ish.shelvingFk = s.code
|
||||
LEFT JOIN vn.parking p ON p.id = s.parkingFk
|
||||
WHERE ish.shelvingFk = ?
|
||||
)sub ON sub.itemFK = ish.itemFk
|
||||
JOIN vn.shelving s ON s.code = ish.shelvingFk
|
||||
JOIN vn.parking p ON p.id = s.parkingFk
|
||||
WHERE ish.shelvingFk <> ? AND sub.created > ish.created AND p.code <> ?`,
|
||||
[shelvingFk, shelvingFk, parking]);
|
||||
)sub ON sub.itemFK = ish.itemFk
|
||||
JOIN vn.shelving s ON s.code = ish.shelvingFk
|
||||
sergiodt marked this conversation as resolved
Outdated
carlosap
commented
Tabulació Tabulació
|
||||
JOIN vn.parking p ON p.id = s.parkingFk
|
||||
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
|
||||
WHERE sub.created > ish.created
|
||||
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]);
|
||||
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...
|
||||
return result[0]['COUNT(ish.id)'] > 0;
|
||||
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
|
||||
};
|
||||
sergiodt marked this conversation as resolved
Outdated
alexm
commented
Aci Aci
alexm
commented
myOptions myOptions
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
He buscat y type int no ho hem gastat mai,
Seria
type: 'integer',
vaig mesclant llenguatges :-)