diff --git a/modules/invoiceIn/back/methods/invoice-in/specs/summary.spec.js b/modules/invoiceIn/back/methods/invoice-in/specs/summary.spec.js new file mode 100644 index 000000000..cf7ccdb1c --- /dev/null +++ b/modules/invoiceIn/back/methods/invoice-in/specs/summary.spec.js @@ -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'); + }); +}); diff --git a/modules/invoiceIn/back/methods/invoice-in/summary.js b/modules/invoiceIn/back/methods/invoice-in/summary.js new file mode 100644 index 000000000..56a105f17 --- /dev/null +++ b/modules/invoiceIn/back/methods/invoice-in/summary.js @@ -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); + }; +};