diff --git a/back/models/dms.json b/back/models/dms.json index bf6e44311..1d9e3ec21 100644 --- a/back/models/dms.json +++ b/back/models/dms.json @@ -3,6 +3,9 @@ "name": "Dms", "description": "Documental Managment system", "base": "VnModel", + "log": { + "showField": "reference" + }, "options": { "mysql": { "table": "dms" diff --git a/db/changes/10140-kings/00-travelThermograph.sql b/db/changes/10140-kings/00-travelThermograph.sql new file mode 100644 index 000000000..c19151a45 --- /dev/null +++ b/db/changes/10140-kings/00-travelThermograph.sql @@ -0,0 +1,7 @@ +ALTER TABLE `vn`.`travelThermograph` +ADD COLUMN `id` INT NOT NULL AUTO_INCREMENT FIRST, +DROP PRIMARY KEY, +ADD PRIMARY KEY (`id`); + +ALTER TABLE `vn`.`travelThermograph` +ADD UNIQUE INDEX `thermograph_created` (`thermographFk` ASC, `created` ASC) VISIBLE; \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index c31510b2c..92580b36e 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1959,4 +1959,5 @@ INSERT INTO `vn`.`travelThermograph`(`thermographFk`, `created`, `warehouseFk`, ('TL.BBA85422', DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 2, 2, 'COOL', 'Ok', NULL), ('TL.BBA85422', CURDATE(), 2, 1, 'COOL', 'can not read the temperature', NULL), ('TZ1905012010', CURDATE(), 1, 1, 'WARM', 'Temperature in range', 5), - ('138350-0', CURDATE(), 1, NULL, 'WARM', NULL, 5); \ No newline at end of file + ('138350-0', DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, NULL, 'WARM', NULL, 5), + ('138350-0', CURDATE(), 1, 1, 'WARM', 'Ok', 5); \ No newline at end of file diff --git a/loopback/common/models/loggable.js b/loopback/common/models/loggable.js index a6d0e8474..d9116a0de 100644 --- a/loopback/common/models/loggable.js +++ b/loopback/common/models/loggable.js @@ -219,7 +219,7 @@ module.exports = function(Self) { userFk: userFk, action: action, changedModel: ctx.Model.definition.name, - changedModelId: changedModelId, + changedModelId: changedModelId, // Model property with an different data type will throw a NaN error changedModelValue: where, oldInstance: oldInstance, newInstance: newInstance diff --git a/modules/travel/back/methods/travel-thermograph/delete.js b/modules/travel/back/methods/travel-thermograph/delete.js new file mode 100644 index 000000000..a8d6bc762 --- /dev/null +++ b/modules/travel/back/methods/travel-thermograph/delete.js @@ -0,0 +1,61 @@ + +module.exports = Self => { + Self.remoteMethod('delete', { + description: 'Delete a invoiceOut', + accessType: 'WRITE', + accepts: { + arg: 'id', + type: 'string', + required: true, + description: 'The invoiceOut id', + http: {source: 'path'} + }, + returns: { + type: 'object', + root: true + }, + http: { + path: '/:id/delete', + verb: 'POST' + } + }); + + Self.delete = async id => { + const models = Self.app.models; + + const targetClaimDms = await models.ClaimDms.findById(id); + const targetDms = await models.Dms.findById(targetClaimDms.dmsFk); + + + const trashDmsType = await models.DmsType.findOne({ + where: {code: 'trash'} + }); + + await models.Dms.removeFile(ctx, targetClaimDms.dmsFk); + await targetClaimDms.destroy(); + + return targetDms.updateAttribute('dmsTypeFk', trashDmsType.id); + + + const transaction = await Self.beginTransaction({}); + try { + let options = {transaction: transaction}; + + let invoiceOut = await Self.findById(id); + let tickets = await Self.app.models.Ticket.find({where: {refFk: invoiceOut.ref}}); + + const promises = []; + tickets.forEach(ticket => { + promises.push(ticket.updateAttribute('refFk', null, options)); + }); + + await Promise.all(promises); + await invoiceOut.destroy(options); + await transaction.commit(); + return tickets; + } catch (e) { + await transaction.rollback(); + throw e; + } + }; +}; diff --git a/modules/travel/back/methods/travel-thermograph/uploadFile.js b/modules/travel/back/methods/travel-thermograph/uploadFile.js index 0cff11204..6ac1b4c09 100644 --- a/modules/travel/back/methods/travel-thermograph/uploadFile.js +++ b/modules/travel/back/methods/travel-thermograph/uploadFile.js @@ -46,7 +46,7 @@ module.exports = Self => { } }); - Self.uploadFile = async(ctx, thermograpId, travelId) => { + Self.uploadFile = async(ctx, thermographId, travelId) => { const models = Self.app.models; const tx = await Self.beginTransaction({}); @@ -57,7 +57,7 @@ module.exports = Self => { const travelThermograph = await models.TravelThermograph.findOne({ where: { - thermographFk: thermograpId, + thermographFk: thermographId, travelFk: null } }, options); @@ -65,7 +65,7 @@ module.exports = Self => { await travelThermograph.updateAttributes({ dmsFk: firstDms.id, travelFk: travelId - }); + }, options); await tx.commit(); diff --git a/modules/travel/back/models/travel-log.json b/modules/travel/back/models/travel-log.json index d21821127..d53be88f1 100644 --- a/modules/travel/back/models/travel-log.json +++ b/modules/travel/back/models/travel-log.json @@ -36,7 +36,7 @@ "type": "Date" }, "changedModelId": { - "type": "Number" + "type": "String" }, "changedModelValue": { "type": "String" diff --git a/modules/travel/back/models/travel-thermograph.json b/modules/travel/back/models/travel-thermograph.json index 18e632d02..80a528655 100644 --- a/modules/travel/back/models/travel-thermograph.json +++ b/modules/travel/back/models/travel-thermograph.json @@ -2,7 +2,9 @@ "name": "TravelThermograph", "base": "Loggable", "log": { - "model":"TravelLog" + "model":"TravelLog", + "relation": "travel", + "showField": "ref" }, "options": { "mysql": { @@ -12,12 +14,11 @@ "properties": { "thermographFk": { "type": "String", - "id": 1, - "description": "Identifier" + "description": "Identifier", + "id": true }, "created": { "type": "Date", - "id": 2, "description": "Identifier" }, "temperature": { diff --git a/modules/travel/back/models/travel.json b/modules/travel/back/models/travel.json index b4f154525..0eafe4010 100644 --- a/modules/travel/back/models/travel.json +++ b/modules/travel/back/models/travel.json @@ -2,7 +2,8 @@ "name": "Travel", "base": "Loggable", "log": { - "model":"TravelLog" + "model":"TravelLog", + "showField": "ref" }, "options": { "mysql": { diff --git a/modules/travel/front/thermograph/locale/es.yml b/modules/travel/front/thermograph/locale/es.yml index d37be5102..d6e634ce3 100644 --- a/modules/travel/front/thermograph/locale/es.yml +++ b/modules/travel/front/thermograph/locale/es.yml @@ -8,7 +8,7 @@ Upload file: Subir fichero Edit file: Editar fichero Upload: Subir File: Fichero -FileDescription: Travel id {{ticketId}} +FileDescription: Travel id {{travelId}} ContentTypesInfo: 'Tipos de archivo permitidos: {{allowedContentTypes}}' Are you sure you want to continue?: ¿Seguro que quieres continuar? Add thermograph: Añadir termógrafo \ No newline at end of file