Bug #422 refactorizar el summary y el card de item y añadir el visible y el available

This commit is contained in:
gerard 2018-08-08 14:44:45 +02:00
parent 1d15e82a64
commit 4b0a75cc0c
2 changed files with 68 additions and 0 deletions

View File

@ -0,0 +1,67 @@
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;
};
};

View File

@ -7,6 +7,7 @@ module.exports = Self => {
require('../methods/item/getDiary')(Self);
require('../methods/item/getLastEntries')(Self);
require('../methods/item/getSummary')(Self);
require('../methods/item/getCard')(Self);
Self.validatesPresenceOf('name', {message: 'Cannot be blank'});
Self.validatesPresenceOf('originFk', {message: 'Cannot be blank'});