From 9bc8687a85e8bf90b27a03bec5345d27291e5e5c Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Tue, 25 Sep 2018 14:39:08 +0200 Subject: [PATCH] Back end dependencies adjusted for #655 --- services/claim/common/models/claim-beginning.js | 3 +-- services/claim/common/models/claim.json | 14 ++++++++++++++ services/loopback/common/methods/ticket/new.js | 4 ++-- .../common/models/obvservation-type.json | 0 .../common/models/ticket-observation.js | 2 +- .../common/models/ticket-observation.json | 0 .../common/models/ticket-tracking.js | 2 +- .../common/models/ticket-tracking.json | 0 services/loopback/common/models/vn-model.js | 4 ++-- services/loopback/server/model-config.json | 9 +++++++++ services/ticket/server/model-config.json | 9 --------- 11 files changed, 30 insertions(+), 17 deletions(-) rename services/{ticket => loopback}/common/models/obvservation-type.json (100%) rename services/{ticket => loopback}/common/models/ticket-observation.js (76%) rename services/{ticket => loopback}/common/models/ticket-observation.json (100%) rename services/{ticket => loopback}/common/models/ticket-tracking.js (58%) rename services/{ticket => loopback}/common/models/ticket-tracking.json (100%) diff --git a/services/claim/common/models/claim-beginning.js b/services/claim/common/models/claim-beginning.js index bce69d531..4cf0e7b70 100644 --- a/services/claim/common/models/claim-beginning.js +++ b/services/claim/common/models/claim-beginning.js @@ -1,6 +1,5 @@ module.exports = Self => { - // Validations - + require('../methods/claim-beginning/importToNewRefundTicket')(Self); Self.validatesUniquenessOf('saleFk', { message: `A claim with that sale already exists` }); diff --git a/services/claim/common/models/claim.json b/services/claim/common/models/claim.json index ab6a4ab05..049dbe3ca 100644 --- a/services/claim/common/models/claim.json +++ b/services/claim/common/models/claim.json @@ -31,6 +31,15 @@ }, "ticketFk": { "type": "Number" + }, + "claimStateFk": { + "type": "Number" + }, + "clientFk": { + "type": "Number" + }, + "workerFk": { + "type": "Number" } }, "relations": { @@ -48,6 +57,11 @@ "type": "belongsTo", "model": "Worker", "foreignKey": "workerFk" + }, + "ticket": { + "type": "belongsTo", + "model": "Ticket", + "foreignKey": "ticketFk" } } } diff --git a/services/loopback/common/methods/ticket/new.js b/services/loopback/common/methods/ticket/new.js index 932f12b56..7c9ee611c 100644 --- a/services/loopback/common/methods/ticket/new.js +++ b/services/loopback/common/methods/ticket/new.js @@ -21,7 +21,7 @@ module.exports = Self => { } }); - Self.new = async params => { + Self.new = async(params, transaction) => { let existsAddress = await Self.app.models.Address.findOne({where: {id: params.addressFk, clientFk: params.clientFk}}); if (!existsAddress) throw new UserError(`This address doesn't exist`); @@ -38,7 +38,7 @@ module.exports = Self => { params.routeFk | null, params.landed, params.userId - ]); + ], transaction); return result[1][0].newTicketId; }; diff --git a/services/ticket/common/models/obvservation-type.json b/services/loopback/common/models/obvservation-type.json similarity index 100% rename from services/ticket/common/models/obvservation-type.json rename to services/loopback/common/models/obvservation-type.json diff --git a/services/ticket/common/models/ticket-observation.js b/services/loopback/common/models/ticket-observation.js similarity index 76% rename from services/ticket/common/models/ticket-observation.js rename to services/loopback/common/models/ticket-observation.js index 3d15e9b0e..34e7e35d4 100644 --- a/services/ticket/common/models/ticket-observation.js +++ b/services/loopback/common/models/ticket-observation.js @@ -1,4 +1,4 @@ -const UserError = require('vn-loopback/common/helpers').UserError; +const UserError = require(`../helpers`).UserError; module.exports = Self => { Self.rewriteDbError(function(err) { diff --git a/services/ticket/common/models/ticket-observation.json b/services/loopback/common/models/ticket-observation.json similarity index 100% rename from services/ticket/common/models/ticket-observation.json rename to services/loopback/common/models/ticket-observation.json diff --git a/services/ticket/common/models/ticket-tracking.js b/services/loopback/common/models/ticket-tracking.js similarity index 58% rename from services/ticket/common/models/ticket-tracking.js rename to services/loopback/common/models/ticket-tracking.js index 2ebef8a9a..0ecd23fba 100644 --- a/services/ticket/common/models/ticket-tracking.js +++ b/services/loopback/common/models/ticket-tracking.js @@ -1,5 +1,5 @@ module.exports = function(Self) { - require('../methods/ticket-tracking/changeState')(Self); + require('../../../ticket/common/methods/ticket-tracking/changeState')(Self); Self.validatesPresenceOf('stateFk', {message: 'State cannot be blank'}); }; diff --git a/services/ticket/common/models/ticket-tracking.json b/services/loopback/common/models/ticket-tracking.json similarity index 100% rename from services/ticket/common/models/ticket-tracking.json rename to services/loopback/common/models/ticket-tracking.json diff --git a/services/loopback/common/models/vn-model.js b/services/loopback/common/models/vn-model.js index deaf64387..2b42d0668 100644 --- a/services/loopback/common/models/vn-model.js +++ b/services/loopback/common/models/vn-model.js @@ -173,10 +173,10 @@ module.exports = function(Self) { }; }; - Self.rawSql = function(query, params, cb) { + Self.rawSql = function(query, params, options = {}, cb) { var connector = this.dataSource.connector; return new Promise(function(resolve, reject) { - connector.execute(query, params, function(error, response) { + connector.execute(query, params, options, function(error, response) { if (cb) cb(error, response); if (error) diff --git a/services/loopback/server/model-config.json b/services/loopback/server/model-config.json index d80927479..684e4aa4e 100644 --- a/services/loopback/server/model-config.json +++ b/services/loopback/server/model-config.json @@ -15,6 +15,15 @@ "ACL": { "dataSource": "salix" }, + "ObservationType": { + "dataSource": "vn" + }, + "TicketObservation": { + "dataSource": "vn" + }, + "TicketTracking": { + "dataSource": "vn" + }, "RoleMapping": { "dataSource": "salix" }, diff --git a/services/ticket/server/model-config.json b/services/ticket/server/model-config.json index dfdee74c1..8f4fa23b5 100644 --- a/services/ticket/server/model-config.json +++ b/services/ticket/server/model-config.json @@ -1,13 +1,4 @@ { - "TicketObservation": { - "dataSource": "vn" - }, - "ObservationType": { - "dataSource": "vn" - }, - "TicketTracking": { - "dataSource": "vn" - }, "TicketPackaging": { "dataSource": "vn" },