salix/modules/item/back/methods/item/get.js

49 lines
1.2 KiB
JavaScript

module.exports = Self => {
Self.remoteMethod('get', {
description: 'Get the data from an item',
accessType: 'READ',
http: {
path: `/get`,
verb: 'GET'
},
accepts: [
{
arg: 'barcode',
type: 'number',
required: true,
},
{
arg: 'warehouseFk',
type: 'number',
required: true,
}
],
returns: {
type: ['object'],
root: true
},
});
Self.get = async(barcode, warehouseFk, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const models = Self.app.models;
const [[itemInfo]] = await Self.rawSql('CALL vn.item_getInfo(?, ?)', [barcode, warehouseFk], myOptions);
if (itemInfo) {
itemInfo.barcodes = await models.ItemBarcode.find({
fields: ['code'],
where: {
itemFk: itemInfo.id
}
});
}
return itemInfo;
};
};