From 8faa1531c62b05630db5af372e36218550b55e37 Mon Sep 17 00:00:00 2001 From: carlosjr Date: Thu, 15 Apr 2021 10:44:25 +0200 Subject: [PATCH] summary route + test --- .../methods/invoice-in/specs/summary.spec.js | 9 ++++ .../back/methods/invoice-in/summary.js | 42 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 modules/invoiceIn/back/methods/invoice-in/specs/summary.spec.js create mode 100644 modules/invoiceIn/back/methods/invoice-in/summary.js 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); + }; +};