From f5b1eb3ccd6a7f9fa4c5fc9a4b7cdc3125cd839b Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 10 Sep 2021 10:38:19 +0200 Subject: [PATCH] feat(closure): send to driver the route report on route closure --- db/dump/fixtures.sql | 7 ++++++- print/methods/closure.js | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 8c1a3c8bc..6f667aa9b 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -6,6 +6,11 @@ ALTER TABLE `vn`.`address` AUTO_INCREMENT = 1; ALTER TABLE `vn`.`zoneGeo` AUTO_INCREMENT = 1; ALTER TABLE `vn`.`ticket` AUTO_INCREMENT = 1; +INSERT INTO `salix`.`AccessToken` (`id`, `ttl`, `created`, `userId`) + VALUES + ('TOTALLY_SECURE_TOKEN', '1209600', CURDATE(), 66); + + INSERT INTO `vn`.`ticketConfig` (`id`, `scopeDays`) VALUES ('1', '6'); @@ -208,7 +213,7 @@ UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 8; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 4 WHERE `id` = 23; UPDATE `vn`.`agencyMode` SET `deliveryMethodFk` = 1 WHERE `id` = 10; -UPDATE `vn`.`agencyMode` SET `web` = 1; +UPDATE `vn`.`agencyMode` SET `web` = 1, `reportMail` = 'no-reply@gothamcity.com'; UPDATE `vn`.`agencyMode` SET `code` = 'refund' WHERE `id` = 23; diff --git a/print/methods/closure.js b/print/methods/closure.js index 4c6f91b58..daa2d5e7c 100644 --- a/print/methods/closure.js +++ b/print/methods/closure.js @@ -143,8 +143,24 @@ module.exports = app => { AND t.refFk IS NULL GROUP BY e.ticketFk`, [reqArgs.routeId]); const ticketIds = tickets.map(ticket => ticket.id); - await closeAll(ticketIds, reqArgs); + + // Send route report to the agency + const agencyMail = await db.findValue(` + SELECT am.reportMail + FROM route r + JOIN agencyMode am ON am.id = r.agencyModeFk + WHERE r.id = ?`, [reqArgs.routeId]); + + if (agencyMail) { + const args = Object.assign({ + routeId: reqArgs.routeId, + recipient: agencyMail + }, reqArgs); + + const email = new Email('driver-route', args); + await email.send(); + } } catch (error) { next(error); }