2018-08-08 12:44:45 +00:00
|
|
|
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 = {};
|
2018-08-08 12:44:45 +00:00
|
|
|
|
2021-07-12 10:54:59 +00:00
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
|
|
|
|
|
|
|
const filter = {
|
2018-08-08 12:44:45 +00:00
|
|
|
include: [
|
2019-01-31 13:14:39 +00:00
|
|
|
{
|
|
|
|
relation: 'itemType',
|
2018-08-08 12:44:45 +00:00
|
|
|
scope: {
|
2022-07-12 09:52:47 +00:00
|
|
|
fields: ['id', 'name', 'workerFk'],
|
2018-08-08 12:44:45 +00:00
|
|
|
include: [{
|
|
|
|
relation: 'worker',
|
|
|
|
scope: {
|
2019-01-31 13:14:39 +00:00
|
|
|
fields: ['userFk'],
|
|
|
|
include: {
|
|
|
|
relation: 'user',
|
|
|
|
scope: {
|
2020-09-03 13:11:16 +00:00
|
|
|
fields: ['name']
|
2019-01-31 13:14:39 +00:00
|
|
|
}
|
|
|
|
}
|
2018-08-08 12:44:45 +00:00
|
|
|
}
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
},
|
2019-01-31 13:14:39 +00:00
|
|
|
{
|
|
|
|
relation: 'tags',
|
2018-08-08 12:44:45 +00:00
|
|
|
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);
|
2018-08-08 12:44:45 +00:00
|
|
|
|
2021-07-12 10:54:59 +00:00
|
|
|
return item ? item : {};
|
2018-08-08 12:44:45 +00:00
|
|
|
};
|
|
|
|
};
|