feat: add getItemTypeWorker endpoint
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
9d7e12d861
commit
0fb7487191
|
@ -0,0 +1,45 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('getItemTypeWorker', {
|
||||
description: 'Returns the workers that appear in itemType',
|
||||
accessType: 'READ',
|
||||
accepts: [],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/getItemTypeWorker`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.getItemTypeWorker = async(ctx, options) => {
|
||||
const myOptions = {};
|
||||
let tx;
|
||||
|
||||
if (typeof options == 'object')
|
||||
Object.assign(myOptions, options);
|
||||
|
||||
if (!myOptions.transaction) {
|
||||
tx = await Self.beginTransaction({});
|
||||
myOptions.transaction = tx;
|
||||
}
|
||||
|
||||
try {
|
||||
const query =
|
||||
`SELECT DISTINCT w.id, w.firstName, w.lastName, u.name, u.nickname
|
||||
FROM itemType it
|
||||
JOIN worker w ON w.id = it.workerFk
|
||||
JOIN account.user u ON u.id = w.id`;
|
||||
|
||||
const result = await Self.rawSql(query);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
return result;
|
||||
} catch (e) {
|
||||
if (tx) await tx.rollback();
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('ticket-request getItemTypeWorker()', () => {
|
||||
it('should return the workers at itemType as result', async() => {
|
||||
const result = await models.TicketRequest.getItemTypeWorker();
|
||||
|
||||
expect(result.length).toEqual(2);
|
||||
});
|
||||
});
|
|
@ -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