4369-ticket.request.create_getItemTypeWorker #1061

Merged
joan merged 6 commits from 4369-ticket.request.create_getItemTypeWorker into dev 2022-10-06 11:30:52 +00:00
4 changed files with 56 additions and 2 deletions
Showing only changes of commit 0fb7487191 - Show all commits

View File

@ -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
Outdated
Review

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)

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)
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
Outdated
Review

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;
}
};
};

View File

@ -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);
});
});

View File

@ -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) {

View File

@ -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>