Merge branch '1934-ticket_stowaway' of verdnatura/salix into dev
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2020-03-27 10:42:33 +00:00 committed by Gitea
commit f5399e1d86
7 changed files with 162 additions and 14 deletions

View File

@ -564,6 +564,10 @@ INSERT INTO `vn`.`ticketObservation`(`id`, `ticketFk`, `observationTypeFk`, `des
(10, 23, 4, 'Reclama ticket: 8'),
(11, 24, 4, 'Reclama ticket: 7');
-- FIX for state hours on local, inter_afterInsert
UPDATE vncontrol.inter SET odbc_date = DATE_ADD(CURDATE(), INTERVAL -10 SECOND);
INSERT INTO `vn`.`ticketTracking`(`ticketFk`, `stateFk`, `workerFk`, `created`)
VALUES
(1, 16, 5 , DATE_ADD(NOW(), INTERVAL -1 MONTH)),

View File

@ -62,6 +62,7 @@
"MESSAGE_INSURANCE_CHANGE": "I have changed the insurence credit of client [{{clientName}} (#{{clientId}})]({{{url}}}) to *{{credit}} €*",
"MESSAGE_CHANGED_PAYMETHOD": "I have changed the pay method for client [{{clientName}} (#{{clientId}})]({{{url}}})",
"Sent units from ticket": "I sent *{{quantity}}* units of [{{concept}} (#{{itemId}})]({{{itemUrl}}}) to *\"{{nickname}}\"* coming from ticket id [#{{ticketId}}]({{{ticketUrl}}})",
"This ticket is not an stowaway anymore": "The ticket id [#{{ticketId}}]({{{ticketUrl}}}) is not an stowaway anymore",
"Customs agent is required for a non UEE member": "Customs agent is required for a non UEE member",
"Incoterms is required for a non UEE member": "Incoterms is required for a non UEE member",
"Client checked as validated despite of duplication": "Client checked as validated despite of duplication from client id {{clientId}}",

View File

@ -125,6 +125,7 @@
"MESSAGE_INSURANCE_CHANGE": "He cambiado el crédito asegurado del cliente [{{clientName}} (#{{clientId}})]({{{url}}}) a *{{credit}} €*",
"MESSAGE_CHANGED_PAYMETHOD": "He cambiado la forma de pago del cliente [{{clientName}} (#{{clientId}})]({{{url}}})",
"Sent units from ticket": "Envio *{{quantity}}* unidades de [{{concept}} (#{{itemId}})]({{{itemUrl}}}) a *\"{{nickname}}\"* provenientes del ticket id [#{{ticketId}}]({{{ticketUrl}}})",
"This ticket is not an stowaway anymore": "El ticket id [#{{ticketId}}]({{{ticketUrl}}}) ha dejado de ser un polizón",
"Client checked as validated despite of duplication": "Cliente comprobado a pesar de que existe el cliente id {{clientId}}",
"ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto",
"Distance must be lesser than 1000": "La distancia debe ser inferior a 1000",

View File

@ -1,6 +1,6 @@
module.exports = Self => {
Self.remoteMethod('deleteStowaway', {
Self.remoteMethodCtx('deleteStowaway', {
description: 'Deletes an stowaway',
accessType: 'WRITE',
accepts: [{
@ -19,21 +19,66 @@ module.exports = Self => {
}
});
Self.deleteStowaway = async id => {
Self.deleteStowaway = async(ctx, id) => {
const models = Self.app.models;
const $t = ctx.req.__; // $translate
const ticket = await Self.findById(id, {
include: [{
relation: 'ship'
}, {
relation: 'stowaway'
}, {
relation: 'client',
scope: {
include: {
relation: 'salesPerson'
}
}
}]
});
let params;
if (ticket.stowaway())
params = [ticket.stowaway().shipFk, ticket.stowaway().id];
else if (ticket.ship())
params = [ticket.ship().shipFk, ticket.ship().id];
let stowawayFk;
let shipFk;
if (ticket.stowaway()) {
shipFk = ticket.stowaway().shipFk;
stowawayFk = ticket.stowaway().id;
} else if (ticket.ship()) {
shipFk = ticket.ship().shipFk;
stowawayFk = ticket.ship().id;
}
return Self.rawSql(`CALL vn.stowaway_unboarding(?, ?)`, params);
const stowaway = await models.Stowaway.findOne({
where: {
id: stowawayFk,
shipFk: shipFk
}
});
const result = await stowaway.destroy();
const state = await models.State.findOne({
where: {
code: 'BOARDING'
}
});
const ticketTracking = await models.TicketTracking.findOne({
where: {
ticketFk: shipFk,
stateFk: state.id
}
});
await ticketTracking.destroy();
const salesPerson = ticket.client().salesPerson();
if (salesPerson) {
const origin = ctx.req.headers.origin;
const message = $t('This ticket is not an stowaway anymore', {
ticketId: stowawayFk,
ticketUrl: `${origin}/#!/ticket/${stowawayFk}/summary`
});
await models.Chat.sendCheckingPresence(ctx, salesPerson.id, message);
}
return result;
};
};

View File

@ -3,40 +3,100 @@ const app = require('vn-loopback/server/server');
describe('ticket deleteStowaway()', () => {
const shipId = 16;
const stowawayId = 17;
const ctx = {
req: {
accessToken: {userId: 18},
headers: {origin: 'http://localhost'}
}
};
ctx.req.__ = (value, params) => {
return params.nickname;
};
afterAll(async() => {
await app.models.Stowaway.rawSql(
`CALL ticketStateUpdate(?, ?)`, [shipId, 'OK']);
await app.models.Stowaway.rawSql(
`CALL ticketStateUpdate(?, ?)`, [stowawayId, 'OK']);
});
it('should create an stowaway', async() => {
await app.models.Stowaway.rawSql(`
INSERT INTO stowaway (id, shipFk) VALUES (?, ?)
`, [stowawayId, shipId]);
await app.models.Stowaway.rawSql(
`CALL ticketStateUpdate(?, ?)`, [shipId, 'BOARDING']);
const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId});
expect(stowawayExists).toEqual(1);
});
it('should confirm that the ship ticket is on "BOARDING" state', async() => {
const shipState = await app.models.TicketLastState.findOne({
where: {
ticketFk: shipId
}
});
expect(shipState.name).toEqual('Embarcando');
});
it('should delete the stowaway from the ship ticket', async() => {
await app.models.Ticket.deleteStowaway(shipId);
await app.models.Ticket.deleteStowaway(ctx, shipId);
const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId});
expect(stowawayExists).toEqual(0);
});
it('should confirm that the ship ticket is not on "BOARDING" state anymore', async() => {
const shipState = await app.models.TicketLastState.findOne({
where: {
ticketFk: shipId
}
});
expect(shipState.name).toEqual('OK');
});
it('should create again an stowaway', async() => {
await app.models.Stowaway.rawSql(`
INSERT INTO stowaway (id, shipFk) VALUES (?, ?)
`, [stowawayId, shipId]);
`, [shipId, stowawayId]);
await app.models.Stowaway.rawSql(
`CALL ticketStateUpdate(?, ?)`, [stowawayId, 'BOARDING']);
const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId});
const stowawayExists = await app.models.Stowaway.count({id: shipId, shipFk: stowawayId});
expect(stowawayExists).toEqual(1);
});
it('should delete the stowaway from the stowaway ticket', async() => {
await app.models.Ticket.deleteStowaway(stowawayId);
it('should confirm that the stowaway ticket is on "BOARDING" state', async() => {
const shipState = await app.models.TicketLastState.findOne({
where: {
ticketFk: stowawayId
}
});
const stowawayExists = await app.models.Stowaway.count({id: stowawayId, shipFk: shipId});
expect(shipState.name).toEqual('Embarcando');
});
it('should delete the stowaway from the stowaway ticket', async() => {
await app.models.Ticket.deleteStowaway(ctx, stowawayId);
const stowawayExists = await app.models.Stowaway.count({id: shipId, shipFk: stowawayId});
expect(stowawayExists).toEqual(0);
});
it('should confirm that the stowaway ticket is not on "BOARDING" state anymore', async() => {
const shipState = await app.models.TicketLastState.findOne({
where: {
ticketFk: stowawayId
}
});
expect(shipState.name).toEqual('OK');
});
});

View File

@ -56,6 +56,9 @@
"TicketState":{
"dataSource": "vn"
},
"TicketLastState":{
"dataSource": "vn"
},
"TicketService":{
"dataSource": "vn"
},

View File

@ -0,0 +1,34 @@
{
"name": "TicketLastState",
"base": "VnModel",
"options": {
"mysql": {
"table": "ticketLastState"
}
},
"properties": {
"name": {
"type": "string"
},
"ticketFk": {
"id": 1,
"type": "Number"
},
"ticketTrackingFk": {
"id": 2,
"type": "Number"
}
},
"relations": {
"ticket": {
"type": "belongsTo",
"model": "Ticket",
"foreignKey": "ticketFk"
},
"ticketTracking": {
"type": "belongsTo",
"model": "TicketTracking",
"foreignKey": "ticketTrackingFk"
}
}
}