This commit is contained in:
parent
4537344790
commit
a155f846c2
|
@ -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();
|
||||||
|
|
|
@ -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);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue