refs #5334 fix ctx
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Satorres 2023-06-20 09:15:37 +02:00
parent 4537344790
commit a155f846c2
2 changed files with 9 additions and 3 deletions

View File

@ -1,5 +1,5 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethodCtx, ('getLeaves', { Self.remoteMethodCtx('getLeaves', {
description: 'Returns the nodes for a department', description: 'Returns the nodes for a department',
accepts: [{ accepts: [{
arg: 'parentId', arg: 'parentId',
@ -21,10 +21,15 @@ module.exports = Self => {
}); });
Self.getLeaves = async(ctx, parentId = null, search) => { 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( let [res] = await Self.rawSql(
`CALL department_getLeaves(?, ?)`, `CALL department_getLeaves(?, ?)`,
[parentId, search], [parentId, search],
{userId: ctx.req.accessToken.userId} myOptions
); );
let map = new Map(); let map = new Map();

View File

@ -1,8 +1,9 @@
const models = require('vn-loopback/server/server').models; const models = require('vn-loopback/server/server').models;
describe('department getLeaves()', () => { describe('department getLeaves()', () => {
const ctx = {req: {accessToken: {userId: 9}}};
it('should return the department and the childs containing the search value', async() => { 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); expect(result.length).toEqual(1);
}); });