Merge pull request '4369-ticket.request.create_getItemTypeWorker' (#1061) from 4369-ticket.request.create_getItemTypeWorker into dev
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
Reviewed-on: #1061
This commit is contained in:
commit
dd9b517883
|
@ -0,0 +1,57 @@
|
|||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('getItemTypeWorker', {
|
||||
description: 'Returns the workers that appear in itemType',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'filter',
|
||||
type: 'Object',
|
||||
description: 'Filter defining where and paginated data',
|
||||
required: true
|
||||
}],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/getItemTypeWorker`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getItemTypeWorker = async(ctx, filter, options) => {
|
||||
const myOptions = {};
|
||||
const conn = Self.dataSource.connector;
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
const query =
|
||||
`SELECT DISTINCT u.nickname
|
||||
FROM itemType it
|
||||
JOIN worker w ON w.id = it.workerFk
|
||||
JOIN account.user u ON u.id = w.id`;
|
||||
|
||||
let stmt = new ParameterizedSQL(query);
|
||||
|
||||
if (filter.where) {
|
||||
const value = filter.where.firstName;
|
||||
const myFilter = {
|
||||
where: {or: [
|
||||
{'w.firstName': {like: `%${value}%`}},
|
||||
{'w.lastName': {like: `%${value}%`}},
|
||||
{'u.name': {like: `%${value}%`}},
|
||||
{'u.nickname': {like: `%${value}%`}}
|
||||
]}
|
||||
};
|
||||
|
||||
stmt.merge(conn.makeSuffix(myFilter));
|
||||
}
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return conn.executeStmt(stmt);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,21 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('ticket-request getItemTypeWorker()', () => {
|
||||
const ctx = {req: {accessToken: {userId: 18}}};
|
||||
|
||||
it('should return the buyer as result', async() => {
|
||||
const filter = {where: {firstName: 'buyer'}};
|
||||
|
||||
const result = await models.TicketRequest.getItemTypeWorker(ctx, filter);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
});
|
||||
|
||||
it('should return the workers at itemType as result', async() => {
|
||||
const filter = {};
|
||||
|
||||
const result = await models.TicketRequest.getItemTypeWorker(ctx, filter);
|
||||
|
||||
expect(result.length).toBeGreaterThan(1);
|
||||
});
|
||||
});
|
|
@ -5,6 +5,7 @@ module.exports = function(Self) {
|
|||
require('../methods/ticket-request/filter')(Self);
|
||||
require('../methods/ticket-request/deny')(Self);
|
||||
require('../methods/ticket-request/confirm')(Self);
|
||||
require('../methods/ticket-request/getItemTypeWorker')(Self);
|
||||
|
||||
Self.observe('before save', async function(ctx) {
|
||||
if (ctx.isNewInstance) {
|
||||
|
|
|
@ -18,9 +18,8 @@
|
|||
<vn-autocomplete
|
||||
label="Buyer"
|
||||
ng-model="$ctrl.ticketRequest.attenderFk"
|
||||
url="Workers/activeWithRole"
|
||||
url="TicketRequests/getItemTypeWorker"
|
||||
show-field="nickname"
|
||||
where="{role: {inq: ['logistic', 'buyer']}}"
|
||||
search-function="{firstName: $search}">
|
||||
</vn-autocomplete>
|
||||
</vn-horizontal>
|
||||
|
|
Loading…
Reference in New Issue