2023-11-30 15:25:13 +00:00
|
|
|
module.exports = Self => {
|
2024-02-19 13:46:42 +00:00
|
|
|
Self.remoteMethod('getAlternative', {
|
2023-11-30 15:25:13 +00:00
|
|
|
description: 'Returns a list of items and possible alternative locations',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'shelvingFk',
|
|
|
|
type: 'string',
|
|
|
|
required: true,
|
|
|
|
}],
|
|
|
|
returns: {
|
2023-12-01 09:14:32 +00:00
|
|
|
type: ['object'],
|
2023-11-30 15:25:13 +00:00
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
2024-02-19 13:46:42 +00:00
|
|
|
path: `/getAlternative`,
|
2023-12-01 10:38:30 +00:00
|
|
|
verb: 'GET'
|
2023-11-30 15:25:13 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2024-02-19 13:46:42 +00:00
|
|
|
Self.getAlternative = async(shelvingFk, options) => {
|
2023-11-30 15:25:13 +00:00
|
|
|
const models = Self.app.models;
|
|
|
|
const myOptions = {};
|
|
|
|
|
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
|
|
|
const filterItemShelvings = {
|
2024-01-17 13:21:50 +00:00
|
|
|
fields: ['id', 'visible', 'itemFk', 'shelvingFk'],
|
2023-11-30 15:25:13 +00:00
|
|
|
where: {shelvingFk},
|
|
|
|
include: [
|
|
|
|
{
|
|
|
|
relation: 'item',
|
|
|
|
scope: {
|
|
|
|
fields: ['longName', 'name', 'size']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
let itemShelvings = await models.ItemShelving.find(filterItemShelvings, myOptions);
|
|
|
|
|
|
|
|
if (itemShelvings) {
|
2024-01-30 13:58:11 +00:00
|
|
|
const [alternatives] = await models.ItemShelving.rawSql('CALL vn.itemShelving_getAlternatives(?)',
|
|
|
|
[shelvingFk], myOptions
|
|
|
|
);
|
2024-01-17 13:21:50 +00:00
|
|
|
return itemShelvings.map(itemShelving => {
|
2023-11-30 15:25:13 +00:00
|
|
|
const item = itemShelving.item();
|
2024-01-30 13:58:11 +00:00
|
|
|
|
2024-01-17 13:21:50 +00:00
|
|
|
const carros = alternatives.filter(alternative => alternative.itemFk == itemShelving.itemFk);
|
2023-12-01 09:14:32 +00:00
|
|
|
|
2023-11-30 15:25:13 +00:00
|
|
|
return {
|
2023-12-01 09:14:32 +00:00
|
|
|
id: itemShelving.id,
|
2024-01-03 11:50:53 +00:00
|
|
|
itemFk: itemShelving.itemFk,
|
2023-12-01 09:14:32 +00:00
|
|
|
longName: item ? item.longName || `${item.name} ${item.size}` : '',
|
|
|
|
quantity: itemShelving.visible,
|
|
|
|
carros
|
2023-11-30 15:25:13 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|