2019-02-22 07:32:18 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('toItem', {
|
|
|
|
description: 'Returns last entries',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'barcode',
|
2021-07-12 10:54:59 +00:00
|
|
|
type: 'number',
|
2019-02-22 07:32:18 +00:00
|
|
|
required: true,
|
|
|
|
description: 'barcode'
|
|
|
|
}],
|
|
|
|
returns: {
|
2021-07-12 10:54:59 +00:00
|
|
|
type: 'number',
|
2019-02-22 07:32:18 +00:00
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:barcode/toItem`,
|
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-07-12 10:54:59 +00:00
|
|
|
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);
|
|
|
|
|
2019-02-22 07:32:18 +00:00
|
|
|
if (item)
|
2021-07-12 10:54:59 +00:00
|
|
|
item = Object.values(item)[0];
|
|
|
|
|
|
|
|
return item;
|
2019-02-22 07:32:18 +00:00
|
|
|
};
|
|
|
|
};
|