7199-devToTest_2316 #2287

Merged
alexm merged 169 commits from 7199-devToTest_2316 into test 2024-04-11 06:25:23 +00:00
1 changed files with 28 additions and 15 deletions
Showing only changes of commit 027aa86662 - Show all commits

View File

@ -1,9 +1,10 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('hasItemOlder', { 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', accessType: 'WRITE',
accepts: [{ accepts: [{
arg: 'shelvingFk', arg: 'shelvingFkIn',
type: 'string', type: 'string',
required: true, required: true,
description: 'Shelving code' description: 'Shelving code'
@ -11,8 +12,17 @@ module.exports = Self => {
{ {
arg: 'parking', arg: 'parking',
type: 'string', type: 'string',
required: true,
description: 'Parking code' description: 'Parking code'
},
{
arg: 'shelvingFkOut',
type: 'string',
description: 'Shelving code'
},
{
arg: 'itemFk',
type: 'int',
description: 'Item id'
}], }],
returns: { returns: {
type: 'boolean', type: 'boolean',
@ -24,21 +34,24 @@ module.exports = Self => {
} }
}); });
Self.hasItemOlder = async(shelvingFk, parking, options) => { Self.hasItemOlder = async(shelvingFkIn, parking, shelvingFkOut, itemFk, options) => {
const result = await Self.rawSql(` const result = await Self.rawSql(`
SELECT COUNT(ish.id) SELECT COUNT(ish.id)
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
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 ish.shelvingFk <> ? AND sub.created > ish.created AND p.code <> ?`, WHERE sub.created > ish.created
[shelvingFk, shelvingFk, parking]); 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]);
return result[0]['COUNT(ish.id)'] > 0; return result[0]['COUNT(ish.id)'] > 0;
}; };
}; };