refs #5334 test front & 1/2 back
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
bb5247c49b
commit
04780e211d
|
@ -1,74 +0,0 @@
|
|||
const buildFilter = require('vn-loopback/util/filter').buildFilter;
|
||||
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('filter', {
|
||||
description: 'Find all instances of the model matched by filter from the data source.',
|
||||
accessType: 'READ',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'filter',
|
||||
type: 'Object',
|
||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
||||
http: {source: 'query'}
|
||||
},
|
||||
{
|
||||
arg: 'search',
|
||||
type: 'String',
|
||||
description: `If it's and integer searchs by id, otherwise it searchs by name`,
|
||||
http: {source: 'query'}
|
||||
},
|
||||
{
|
||||
arg: 'id',
|
||||
type: 'Integer',
|
||||
description: 'The department id',
|
||||
http: {source: 'query'}
|
||||
},
|
||||
{
|
||||
arg: 'code',
|
||||
type: 'String',
|
||||
description: 'The department code',
|
||||
http: {source: 'query'}
|
||||
},
|
||||
{
|
||||
arg: 'name',
|
||||
type: 'String',
|
||||
description: 'The department name',
|
||||
http: {source: 'query'}
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: ['Object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/filter`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.filter = async(ctx, filter) => {
|
||||
let conn = Self.dataSource.connector;
|
||||
let where = buildFilter(ctx.args, (param, value) => {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
return /^\d+$/.test(value)
|
||||
? {'id': value}
|
||||
: {or: [
|
||||
{'code': {like: `%${value}%`}},
|
||||
{'name': {like: `%${value}%`}}
|
||||
]};
|
||||
case 'id':
|
||||
return {'id': value};
|
||||
case 'code':
|
||||
return {'code': value};
|
||||
case 'name':
|
||||
return {'name': {like: `%${value}%`}};
|
||||
}
|
||||
});
|
||||
|
||||
filter = mergeFilters(ctx.args.filter, {where});
|
||||
const departments = await Self.app.models.Department.find(filter);
|
||||
return departments;
|
||||
};
|
||||
};
|
|
@ -25,6 +25,7 @@ module.exports = Self => {
|
|||
`CALL department_getLeaves(?, ?)`,
|
||||
[parentId, search]
|
||||
);
|
||||
|
||||
let map = new Map();
|
||||
for (let node of res) {
|
||||
if (!map.has(node.parentFk))
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('department getLeaves()', () => {
|
||||
it('should return the department and the childs containing the search value', async() => {
|
||||
const tx = await models.Zone.beginTransaction({});
|
||||
|
||||
try {
|
||||
let result = await models.Zone.getLeaves(null, '31');
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
|
||||
await tx.rollback();
|
||||
} catch (e) {
|
||||
await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
});
|
||||
});
|
|
@ -0,0 +1,26 @@
|
|||
import './index.js';
|
||||
|
||||
describe('vnWorkerDepartmentDescriptor', () => {
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
|
||||
beforeEach(ngModule('worker'));
|
||||
|
||||
beforeEach(inject(($componentController, _$httpBackend_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
controller = $componentController('vnWorkerDepartmentDescriptor', {$element: null});
|
||||
}));
|
||||
|
||||
describe('loadData()', () => {
|
||||
it(`should perform a get query to store the department data into the controller`, () => {
|
||||
const id = '31';
|
||||
const response = 'foo';
|
||||
|
||||
$httpBackend.expectRoute('GET', `Departments/${id}`).respond(response);
|
||||
controller.id = id;
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.department).toEqual(response);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue