2024-03-04 17:35:36 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('hasItemOlder', {
|
2024-03-22 09:08:20 +00:00
|
|
|
description:
|
|
|
|
'Get boolean if any or specific item of the shelving has older created in another shelving or parking',
|
2024-03-04 17:35:36 +00:00
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: [{
|
2024-03-22 09:08:20 +00:00
|
|
|
arg: 'shelvingFkIn',
|
2024-03-04 17:35:36 +00:00
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
description: 'Shelving code'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'parking',
|
|
|
|
type: 'string',
|
|
|
|
description: 'Parking code'
|
2024-03-22 09:08:20 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'shelvingFkOut',
|
|
|
|
type: 'string',
|
|
|
|
description: 'Shelving code'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
arg: 'itemFk',
|
|
|
|
type: 'int',
|
|
|
|
description: 'Item id'
|
2024-03-04 17:35:36 +00:00
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: 'boolean',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/hasItemOlder`,
|
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-03-22 09:08:20 +00:00
|
|
|
Self.hasItemOlder = async(shelvingFkIn, parking, shelvingFkOut, itemFk, options) => {
|
2024-03-04 17:35:36 +00:00
|
|
|
const result = await Self.rawSql(`
|
|
|
|
SELECT COUNT(ish.id)
|
2024-03-22 09:08:20 +00:00
|
|
|
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
|
|
|
|
LEFT JOIN vn.parking p ON p.id = s.parkingFk
|
2024-03-04 17:35:36 +00:00
|
|
|
WHERE ish.shelvingFk = ?
|
2024-03-22 09:08:20 +00:00
|
|
|
)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 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]);
|
2024-03-04 17:35:36 +00:00
|
|
|
return result[0]['COUNT(ish.id)'] > 0;
|
|
|
|
};
|
|
|
|
};
|