From a155f846c21aa73b0a4d4445f533b9bb2037b4a1 Mon Sep 17 00:00:00 2001 From: carlossa Date: Tue, 20 Jun 2023 09:15:37 +0200 Subject: [PATCH] refs #5334 fix ctx --- modules/worker/back/methods/department/getLeaves.js | 9 +++++++-- .../back/methods/department/specs/getLeaves.spec.js | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/methods/department/getLeaves.js b/modules/worker/back/methods/department/getLeaves.js index 802a2d41d..bf7c83bb0 100644 --- a/modules/worker/back/methods/department/getLeaves.js +++ b/modules/worker/back/methods/department/getLeaves.js @@ -1,5 +1,5 @@ module.exports = Self => { - Self.remoteMethodCtx, ('getLeaves', { + Self.remoteMethodCtx('getLeaves', { description: 'Returns the nodes for a department', accepts: [{ arg: 'parentId', @@ -21,10 +21,15 @@ module.exports = Self => { }); Self.getLeaves = async(ctx, parentId = null, search) => { + const myOptions = {userId: ctx.req.accessToken.userId}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + let [res] = await Self.rawSql( `CALL department_getLeaves(?, ?)`, [parentId, search], - {userId: ctx.req.accessToken.userId} + myOptions ); let map = new Map(); diff --git a/modules/worker/back/methods/department/specs/getLeaves.spec.js b/modules/worker/back/methods/department/specs/getLeaves.spec.js index 5972a9b4c..fb7c84ff4 100644 --- a/modules/worker/back/methods/department/specs/getLeaves.spec.js +++ b/modules/worker/back/methods/department/specs/getLeaves.spec.js @@ -1,8 +1,9 @@ const models = require('vn-loopback/server/server').models; describe('department getLeaves()', () => { + const ctx = {req: {accessToken: {userId: 9}}}; it('should return the department and the childs containing the search value', async() => { - let result = await models.Department.getLeaves(null, 'INFORMATICA'); + let result = await models.Department.getLeaves(ctx, null, 'INFORMATICA'); expect(result.length).toEqual(1); });