summary route + test

This commit is contained in:
Carlos Jimenez Ruiz 2021-04-15 10:44:25 +02:00
parent 5931dd238c
commit 8faa1531c6
2 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,9 @@
const app = require('vn-loopback/server/server');
describe('invoiceIn summary()', () => {
it('should return a summary object containing data from one invoiceIn', async() => {
const summary = await app.models.InvoiceIn.summary(1);
expect(summary.invoiceIn.supplierRef).toEqual('1234');
});
});

View File

@ -0,0 +1,42 @@
module.exports = Self => {
Self.remoteMethod('summary', {
description: 'The invoiceIn summary',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'The invoiceIn id',
http: {source: 'path'}
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/:id/summary`,
verb: 'GET'
}
});
Self.summary = async id => {
const filter = {
include: [
{
relation: 'company',
scope: {
fields: ['id', 'code']
}
},
{
relation: 'supplier',
scope: {
fields: ['id', 'name']
}
}
]
};
return Self.app.models.InvoiceIn.findById(id, filter);
};
};