salix/modules/item/back/methods/item/getCard.js

67 lines
1.9 KiB
JavaScript
Raw Normal View History

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'
}
});
2021-07-12 10:54:59 +00:00
Self.getCard = async(id, options) => {
const myOptions = {};
2021-07-12 10:54:59 +00:00
if (typeof options == 'object')
Object.assign(myOptions, options);
const filter = {
include: [
{
relation: 'itemType',
scope: {
2022-07-12 09:52:47 +00:00
fields: ['id', 'name', 'workerFk'],
include: [{
relation: 'worker',
scope: {
fields: ['userFk'],
include: {
relation: 'user',
scope: {
2020-09-03 13:11:16 +00:00
fields: ['name']
}
}
}
}]
}
},
{
relation: 'tags',
scope: {
fields: ['id', 'value', 'tagFk'],
include: [{
relation: 'tag',
scope: {
fields: ['id', 'name']
}
}]
}
}
]
};
2021-07-12 10:54:59 +00:00
const item = await Self.app.models.Item.findById(id, filter, myOptions);
2021-07-12 10:54:59 +00:00
return item ? item : {};
};
};