68 lines
1.9 KiB
JavaScript
68 lines
1.9 KiB
JavaScript
|
module.exports = Self => {
|
||
|
Self.remoteMethod('getCard', {
|
||
|
description: 'Return the card for a given item id',
|
||
|
accessType: 'READ',
|
||
|
accepts: [{
|
||
|
arg: 'id',
|
||
|
type: 'number',
|
||
|
required: true,
|
||
|
description: 'The item id',
|
||
|
http: {source: 'path'}
|
||
|
}],
|
||
|
returns: {
|
||
|
type: 'object',
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/:id/getCard`,
|
||
|
verb: 'GET'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.getCard = async id => {
|
||
|
let item = {};
|
||
|
|
||
|
// Item basic data
|
||
|
let filter = {
|
||
|
where: {id: id},
|
||
|
include: [
|
||
|
{relation: 'itemType',
|
||
|
scope: {
|
||
|
fields: ['id', 'name', 'workerFk', 'warehouseFk'],
|
||
|
include: [{
|
||
|
relation: 'worker',
|
||
|
scope: {
|
||
|
fields: ['id', 'name', 'firstName']
|
||
|
}
|
||
|
}]
|
||
|
}
|
||
|
},
|
||
|
{relation: 'tags',
|
||
|
scope: {
|
||
|
fields: ['id', 'value', 'tagFk'],
|
||
|
include: [{
|
||
|
relation: 'tag',
|
||
|
scope: {
|
||
|
fields: ['id', 'name']
|
||
|
}
|
||
|
}]
|
||
|
}
|
||
|
}
|
||
|
]
|
||
|
};
|
||
|
[item] = await Self.app.models.Item.find(filter);
|
||
|
|
||
|
// Visible Avaible
|
||
|
let query = `
|
||
|
CALL vn.getItemVisibleAvailable(?,curdate(),?,?)`;
|
||
|
|
||
|
let options = [item.id, item.itemType().warehouseFk, false];
|
||
|
let [res] = await Self.rawSql(query, options);
|
||
|
|
||
|
item.available = res[0].available ? res[0].available : '-';
|
||
|
item.visible = res[0].visible ? res[0].visible : '-';
|
||
|
|
||
|
return item;
|
||
|
};
|
||
|
};
|