36 lines
844 B
JavaScript
36 lines
844 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, options) => {
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
const query = `SELECT vn.barcodeToItem(?)`;
|
|
let [item] = await Self.rawSql(query, [barcode], myOptions);
|
|
|
|
if (item)
|
|
item = Object.values(item)[0];
|
|
|
|
return item;
|
|
};
|
|
};
|