salix/modules/supplier/back/methods/supplier/getSummary.js

115 lines
3.2 KiB
JavaScript

module.exports = Self => {
Self.remoteMethod('getSummary', {
description: 'Returns the supplier summary',
accessType: 'READ',
accepts: {
arg: 'id',
type: 'number',
required: true,
description: 'The supplier id',
http: {source: 'path'}
},
returns: {
type: 'object',
root: true
},
http: {
path: `/:id/getSummary`,
verb: 'GET'
}
});
Self.getSummary = async id => {
let filter = {
where: {id: id},
fields: [
'id',
'name',
'nickname',
'isReal',
'isActive',
'note',
'nif',
'street',
'city',
'postCode',
'provinceFk',
'countryFk',
'payMethodFk',
'payDemFk',
'payDay',
'account',
'sageTaxTypeFk',
'sageTransactionTypeFk',
'sageWithholdingFk',
'workerFk',
'supplierActivityFk',
'healthRegister'
],
include: [
{
relation: 'province',
scope: {
fields: ['id', 'name']
}
},
{
relation: 'country',
scope: {
fields: ['id', 'name', 'code']
}
},
{
relation: 'payMethod',
scope: {
fields: ['id', 'name']
}
},
{
relation: 'payDem',
scope: {
fields: ['id', 'payDem']
}
},
{
relation: 'sageTaxType',
scope: {
fields: ['id', 'vat']
}
},
{
relation: 'sageTransactionType',
scope: {
fields: ['id', 'transaction']
}
},
{
relation: 'sageWithholding',
scope: {
fields: ['id', 'withholding']
}
},
{
relation: 'worker',
scope: {
fields: ['id'],
include: {
relation: 'user',
scope: {
fields: ['nickname']
}
}
}
},
{
relation: 'supplierActivity',
scope: {
fields: ['code', 'name']
}
}
]
};
return Self.app.models.Supplier.findOne(filter);
};
};