4369-ticket.request.create_getItemTypeWorker #1061
|
@ -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
|
||||
vicent marked this conversation as resolved
Outdated
|
||||
JOIN account.user u ON u.id = w.id`;
|
||||
|
||||
const result = await Self.rawSql(query);
|
||||
|
||||
if (tx) await tx.commit();
|
||||
|
||||
vicent marked this conversation as resolved
Outdated
joan
commented
No necesitas seleccionar todas las columnas por las que filtras con el where. Dejar solo las necesarias No necesitas seleccionar todas las columnas por las que filtras con el where. Dejar solo las necesarias
|
||||
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
En este caso no necesitas crear una transacción, ya que la ruta no hace modificaciones, ni tampoco requiere que esté transaccionado. (Pero si es correcto aceptar transacciones desde el options, linea 28)