67 lines
1.9 KiB
JavaScript
67 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, options) => {
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
const filter = {
|
|
include: [
|
|
{
|
|
relation: 'itemType',
|
|
scope: {
|
|
fields: ['id', 'name', 'workerFk'],
|
|
include: [{
|
|
relation: 'worker',
|
|
scope: {
|
|
fields: ['id'],
|
|
include: {
|
|
relation: 'user',
|
|
scope: {
|
|
fields: ['name']
|
|
}
|
|
}
|
|
}
|
|
}]
|
|
}
|
|
},
|
|
{
|
|
relation: 'tags',
|
|
scope: {
|
|
fields: ['id', 'value', 'tagFk'],
|
|
include: [{
|
|
relation: 'tag',
|
|
scope: {
|
|
fields: ['id', 'name']
|
|
}
|
|
}]
|
|
}
|
|
}
|
|
]
|
|
};
|
|
const item = await Self.app.models.Item.findById(id, filter, myOptions);
|
|
|
|
return item ? item : {};
|
|
};
|
|
};
|