merge paso 2

This commit is contained in:
Javi Gallego 2019-03-14 10:43:14 +01:00
parent 3776e0588c
commit 94cc7af8b2
7 changed files with 24 additions and 37 deletions

View File

@ -19,7 +19,7 @@ module.exports = Self => {
});
Self.getAgenciesWithWarehouse = async filter => {
let query = `CALL vn.agencyHourGetWarehouse(?, ?, ?)`;
let query = `CALL vn.zoneGetWarehouse(?, ?, ?)`;
let result = await Self.rawSql(query, [filter.addressFk, filter.landed, filter.warehouseFk]);
return result;

View File

@ -19,10 +19,9 @@ module.exports = Self => {
});
Self.getShipped = async params => {
let query = `CALL vn.zoneGetShipped(?, ?, ?);
SELECT * FROM tmp.zoneGetShipped`;
let result = await Self.rawSql(query, [params.landed, params.addressFk, params.agencyModeFk]);
let query = `CALL vn.zoneGetShipped(?, ?, ?, ?)`;
let result = await Self.rawSql(query, [params.landed, params.addressFk, params.agencyModeFk, 1]);
return result[1][0].shipped || null;
return result[0][0].shipped || null;
};
};

View File

@ -1,6 +1,3 @@
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethod('getShipped', {
description: 'Returns ticket available shipment date',
@ -23,24 +20,14 @@ module.exports = Self => {
});
Self.getShipped = async data => {
let stmts = [];
let agencyMode = await Self.app.models.AgencyMode.findById(data.agencyModeFk);
let query = `CALL vn.zoneGetShipped(?, ?, ?, ?)`;
let [shipped] = await Self.rawSql(query, [
data.landed,
data.addressFk,
data.agencyModeFk,
data.warehouseFk
]);
stmts.push(new ParameterizedSQL(
`CALL vn.zoneGetShipped(?, ?, ?)`, [
data.landed,
data.addressFk,
agencyMode.agencyFk
]
));
mirar si en otros modulos se usa sin tabla temporal
let rsIndex = stmts.push(`
SELECT * FROM tmp.zoneGetShipped`) - 1;
let sql = ParameterizedSQL.join(stmts, ';');
let shipped = await Self.rawStmt(sql);
return shipped[rsIndex][0];
return shipped[0].shipped || null;
};
};

View File

@ -39,11 +39,11 @@ module.exports = Self => {
if (!address)
throw new UserError(`This address doesn't exist`);
let agency;
let agencyMode;
if (params && params.agencyModeFk)
agency = await Self.app.models.AgencyMode.findById(params.agencyModeFk);
agencyMode = await Self.app.models.AgencyMode.findById(params.agencyModeFk);
if (address.client().type().code === 'normal' && (!agency || agency.code != 'refund')) {
if (address.client().type().code === 'normal' && (!agencyMode || agencyMode.name != 'refund')) {
if (address.client().isFreezed)
throw new UserError(`You can't create a ticket for a frozen client`);
@ -59,7 +59,7 @@ module.exports = Self => {
params.shipped = await Self.app.models.Agency.getShipped({
landed: params.landed,
addressFk: address.id,
agencyModeFk: agency.agencyFk
agencyModeFk: agency.agencyModeFk
});
}
@ -67,12 +67,10 @@ module.exports = Self => {
params.landed = await Self.app.models.Agency.getLanded({
shipped: params.shipped,
addressFk: address.id,
agencyModeFk: agency.agencyFk,
warehouseFk: params.warehouseFk
agencyModeFk: params.agencyModeFk
});
}
if (!params.userId && ctx.req && ctx.req.accessToken.userId)
params.userId = ctx.req.accessToken.userId;

View File

@ -5,7 +5,8 @@ describe('ticket getShipped()', () => {
let data = {
landed: new Date(),
addressFk: 121,
agencyModeFk: 7
agencyModeFk: 7,
warehouseFk: 1
};
let result = await app.models.Ticket.getShipped(data);
@ -19,7 +20,8 @@ describe('ticket getShipped()', () => {
let data = {
landed: newDate,
addressFk: 121,
agencyModeFk: 7
agencyModeFk: 7,
warehouseFk: 1
};
let result = await app.models.Ticket.getShipped(data);

View File

@ -82,7 +82,8 @@ class Controller {
let data = {
landed: value,
addressFk: this.ticket.addressFk,
agencyModeFk: this.ticket.agencyModeFk
agencyModeFk: this.ticket.agencyModeFk,
warehouseFk: this.ticket.warehouseFk
};
let query = `/api/Tickets/getShipped`;

View File

@ -37,7 +37,7 @@
disabled="!$ctrl.clientFk || !$ctrl.landed || !$ctrl.warehouseFk"
data="$ctrl._availableAgencies"
label="Agency"
show-field="agency"
show-field="agencyMode"
value-field="id"
field="$ctrl.ticket.agencyModeFk">
</vn-autocomplete>