7226-testToMaster_2416 #2320

Merged
alexm merged 188 commits from 7226-testToMaster_2416 into master 2024-04-18 05:39:36 +00:00
1 changed files with 14 additions and 12 deletions
Showing only changes of commit 22f78dbb91 - Show all commits

View File

@ -1,3 +1,4 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('hasItemOlder', { Self.remoteMethod('hasItemOlder', {
description: description:
@ -35,23 +36,24 @@ module.exports = Self => {
}); });
Self.hasItemOlder = async(shelvingFkIn, parking, shelvingFkOut, itemFk, options) => { Self.hasItemOlder = async(shelvingFkIn, parking, shelvingFkOut, itemFk, options) => {
if (!parking && !shelvingFkOut) throw new UserError('Missing data: parking or shelving');
const result = await Self.rawSql(` const result = await Self.rawSql(`
SELECT COUNT(ish.id) SELECT COUNT(ish.id) countItemOlder
FROM vn.itemShelving ish FROM vn.itemShelving ish
JOIN ( JOIN (
SELECT ish.itemFk, created,shelvingFk, p.code SELECT ish.itemFk, created,shelvingFk, p.code
FROM vn.itemShelving ish FROM vn.itemShelving ish
JOIN vn.shelving s ON ish.shelvingFk = s.code JOIN vn.shelving s ON ish.shelvingFk = s.code
LEFT JOIN vn.parking p ON p.id = s.parkingFk LEFT JOIN vn.parking p ON p.id = s.parkingFk
WHERE ish.shelvingFk = ? WHERE ish.shelvingFk = ?
)sub ON sub.itemFK = ish.itemFk )sub ON sub.itemFK = ish.itemFk
JOIN vn.shelving s ON s.code = ish.shelvingFk JOIN vn.shelving s ON s.code = ish.shelvingFk
JOIN vn.parking p ON p.id = s.parkingFk JOIN vn.parking p ON p.id = s.parkingFk
WHERE sub.created > ish.created WHERE sub.created > ish.created
AND (p.code <> ? OR ? IS NULL) AND (p.code <> ? OR ? IS NULL)
AND (ish.shelvingFk <> ? OR ? IS NULL) AND (ish.shelvingFk <> ? OR ? IS NULL)
AND (ish.itemFk <> ? OR ? IS NULL)`, AND (ish.itemFk <> ? OR ? IS NULL)`,
[shelvingFkIn, parking, parking, shelvingFkOut, shelvingFkOut, itemFk, itemFk]); [shelvingFkIn, parking, parking, shelvingFkOut, shelvingFkOut, itemFk, itemFk]);
return result[0]['COUNT(ish.id)'] > 0; return result[0]['countItemOlder'] > 0;
}; };
}; };