92 lines
2.7 KiB
JavaScript
92 lines
2.7 KiB
JavaScript
module.exports = Self => {
|
|
Self.remoteMethod('getEntry', {
|
|
description: 'Returns an entry',
|
|
accessType: 'READ',
|
|
accepts: {
|
|
arg: 'id',
|
|
type: 'number',
|
|
required: true,
|
|
description: 'The entry id',
|
|
http: {source: 'path'}
|
|
},
|
|
returns: {
|
|
type: 'object',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: `/:id/getEntry`,
|
|
verb: 'GET'
|
|
}
|
|
});
|
|
|
|
Self.getEntry = async(id, options) => {
|
|
const models = Self.app.models;
|
|
const myOptions = {};
|
|
|
|
if (typeof options == 'object')
|
|
Object.assign(myOptions, options);
|
|
|
|
const filter = {
|
|
where: {id: id},
|
|
include: [
|
|
{
|
|
relation: 'supplier',
|
|
scope: {
|
|
fields: ['id', 'nickname']
|
|
}
|
|
},
|
|
{
|
|
relation: 'travel',
|
|
scope: {
|
|
fields: [
|
|
'id',
|
|
'name',
|
|
'shipped',
|
|
'landed',
|
|
'agencyModeFk',
|
|
'warehouseOutFk',
|
|
'warehouseInFk',
|
|
'isReceived',
|
|
'isDelivered',
|
|
'ref'],
|
|
include: [
|
|
{
|
|
relation: 'agency',
|
|
scope: {
|
|
fields: ['name']
|
|
}
|
|
},
|
|
{
|
|
relation: 'warehouseOut',
|
|
scope: {
|
|
fields: ['name']
|
|
}
|
|
},
|
|
{
|
|
relation: 'warehouseIn',
|
|
scope: {
|
|
fields: ['name']
|
|
}
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
relation: 'currency',
|
|
scope: {
|
|
fields: ['id', 'name']
|
|
}
|
|
},
|
|
{
|
|
relation: 'company',
|
|
scope: {
|
|
fields: ['id', 'code']
|
|
}
|
|
}
|
|
],
|
|
};
|
|
|
|
return models.Entry.findOne(filter, myOptions);
|
|
};
|
|
};
|