1934 - Moved procedure logic to method
gitea/salix/pipeline/head This commit has test failures Details

This commit is contained in:
Joan Sanchez 2020-03-26 14:45:38 +01:00
parent efcecd0995
commit 835c415ba7
3 changed files with 55 additions and 8 deletions

View File

@ -62,6 +62,7 @@
"MESSAGE_INSURANCE_CHANGE": "I have changed the insurence credit of client [{{clientName}} (#{{clientId}})]({{{url}}}) to *{{credit}} €*", "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}}})", "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}}})", "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", "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", "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}}", "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_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}}})", "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}}})", "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}}", "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", "ORDER_ROW_UNAVAILABLE": "No hay disponibilidad de este producto",
"Distance must be lesser than 1000": "La distancia debe ser inferior a 1000", "Distance must be lesser than 1000": "La distancia debe ser inferior a 1000",

View File

@ -1,6 +1,6 @@
module.exports = Self => { module.exports = Self => {
Self.remoteMethod('deleteStowaway', { Self.remoteMethodCtx('deleteStowaway', {
description: 'Deletes an stowaway', description: 'Deletes an stowaway',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ 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, { const ticket = await Self.findById(id, {
include: [{ include: [{
relation: 'ship' relation: 'ship'
}, { }, {
relation: 'stowaway' relation: 'stowaway'
}, {
relation: 'client',
scope: {
include: {
relation: 'salesPerson'
}
}
}] }]
}); });
let params; let stowawayFk;
if (ticket.stowaway()) let shipFk;
params = [ticket.stowaway().shipFk, ticket.stowaway().id]; if (ticket.stowaway()) {
else if (ticket.ship()) shipFk = ticket.stowaway().shipFk;
params = [ticket.ship().shipFk, ticket.ship().id]; 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;
}; };
}; };