salix/modules/item/back/methods/item-barcode/toItem.js

29 lines
700 B
JavaScript

module.exports = Self => {
Self.remoteMethod('toItem', {
description: 'Returns last entries',
accessType: 'READ',
accepts: [{
arg: 'barcode',
type: 'Number',
required: true,
description: 'barcode'
}],
returns: {
type: 'Number',
root: true
},
http: {
path: `/:barcode/toItem`,
verb: 'GET'
}
});
Self.toItem = async barcode => {
let query = `SELECT vn.barcodeToItem(?)`;
let [item] = await Self.rawSql(query, [barcode]);
if (item)
item = Object.values(item);
return item[0];
};
};