From 52f18435804ac32fa81f267cf631409240aa8b0a Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 9 Nov 2023 15:00:49 +0100 Subject: [PATCH 1/3] ref #5835 due day new and fixtures --- db/dump/fixtures.sql | 4 +- .../back/methods/invoice-in-due-day/new.js | 37 +++++++++++++++++++ .../back/models/invoice-in-due-day.js | 3 ++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 modules/invoiceIn/back/methods/invoice-in-due-day/new.js create mode 100644 modules/invoiceIn/back/models/invoice-in-due-day.js diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index d70279e7d..f57b302f3 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2880,7 +2880,9 @@ INSERT INTO `vn`.`report` (`id`, `name`, `paperSizeFk`, `method`) INSERT INTO `vn`.`payDemDetail` (`id`, `detail`) VALUES - (1, 1); + (1, 1), + (2, 20), + (7, 1); INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`, `payMethodFk`, `businessTypeFk`) VALUES diff --git a/modules/invoiceIn/back/methods/invoice-in-due-day/new.js b/modules/invoiceIn/back/methods/invoice-in-due-day/new.js new file mode 100644 index 000000000..37d2f6d05 --- /dev/null +++ b/modules/invoiceIn/back/methods/invoice-in-due-day/new.js @@ -0,0 +1,37 @@ +module.exports = Self => { + Self.remoteMethodCtx('new', { + description: 'Creates a new invoiceIn due day', + accessType: 'WRITE', + accepts: { + arg: 'id', + type: 'number', + required: true, + description: 'The invoiceIn id', + }, + http: { + path: '/new', + verb: 'POST' + } + }); + + Self.new = async(ctx, id, options) => { + let tx; + const myOptions = {userId: ctx.req.accessToken.userId}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + await Self.rawSql(`CALL vn.invoiceInDueDay_calculate(?)`, [id], myOptions); + if (tx) await tx.commit(); + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/invoiceIn/back/models/invoice-in-due-day.js b/modules/invoiceIn/back/models/invoice-in-due-day.js new file mode 100644 index 000000000..2375c6566 --- /dev/null +++ b/modules/invoiceIn/back/models/invoice-in-due-day.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/invoice-in-due-day/new')(Self); +}; From 513562955b1d7b11aef24d4e348f83250c70490b Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 9 Nov 2023 15:53:41 +0100 Subject: [PATCH 2/3] ref #5835 test back --- .../invoice-in-due-day/specs/new.spec.js | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js diff --git a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js new file mode 100644 index 000000000..f2f04b993 --- /dev/null +++ b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js @@ -0,0 +1,51 @@ +const LoopBackContext = require('loopback-context'); +const models = require('vn-loopback/server/server').models; + +describe('invoiceInDueDay new()', () => { + beforeAll(async() => { + const activeCtx = { + accessToken: {userId: 9}, + http: { + req: { + headers: {origin: 'http://localhost'} + } + } + }; + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + }); + + it('should correctly create a new due day', async() => { + const userId = 9; + const invoiceInFk = 6; + + const ctx = { + req: { + + accessToken: {userId: userId}, + headers: {origin: 'http://localhost:5000'}, + } + }; + + const tx = await models.InvoiceIn.beginTransaction({}); + const options = {transaction: tx}; + + try { + await models.InvoiceInDueDay.destroyAll({ + invoiceInFk + }, options); + + await models.InvoiceInDueDay.new(ctx, invoiceInFk, options); + + const result = await models.InvoiceInDueDay.find({where: {invoiceInFk}}, options); + + expect(result).toBeDefined(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); From dd11cf53273e6f52e0d27c37afe2ed61a23adcb5 Mon Sep 17 00:00:00 2001 From: jorgep Date: Tue, 21 Nov 2023 09:03:25 +0100 Subject: [PATCH 3/3] ref #5835 fix test --- .../back/methods/invoice-in-due-day/specs/new.spec.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js index f2f04b993..c188a511d 100644 --- a/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js +++ b/modules/invoiceIn/back/methods/invoice-in-due-day/specs/new.spec.js @@ -5,11 +5,6 @@ describe('invoiceInDueDay new()', () => { beforeAll(async() => { const activeCtx = { accessToken: {userId: 9}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } }; spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: activeCtx @@ -24,7 +19,6 @@ describe('invoiceInDueDay new()', () => { req: { accessToken: {userId: userId}, - headers: {origin: 'http://localhost:5000'}, } };