45 lines
1.5 KiB
JavaScript
45 lines
1.5 KiB
JavaScript
|
module.exports = Self => {
|
||
|
Self.remoteMethod('hasItemOlder', {
|
||
|
description: 'Get boolean if any item of the shelving has older created in another shelving ',
|
||
|
accessType: 'WRITE',
|
||
|
accepts: [{
|
||
|
arg: 'shelvingFk',
|
||
|
type: 'string',
|
||
|
required: true,
|
||
|
description: 'Shelving code'
|
||
|
},
|
||
|
{
|
||
|
arg: 'parking',
|
||
|
type: 'string',
|
||
|
required: true,
|
||
|
description: 'Parking code'
|
||
|
}],
|
||
|
returns: {
|
||
|
type: 'boolean',
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/hasItemOlder`,
|
||
|
verb: 'GET'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.hasItemOlder = async(shelvingFk, parking, options) => {
|
||
|
const result = await Self.rawSql(`
|
||
|
SELECT COUNT(ish.id)
|
||
|
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
|
||
|
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]);
|
||
|
return result[0]['COUNT(ish.id)'] > 0;
|
||
|
};
|
||
|
};
|