diff --git a/back/methods/dms/removeFile.js b/back/methods/dms/removeFile.js
index 350bea6bc..93fae9728 100644
--- a/back/methods/dms/removeFile.js
+++ b/back/methods/dms/removeFile.js
@@ -22,8 +22,10 @@ module.exports = Self => {
Self.removeFile = async(ctx, id) => {
const models = Self.app.models;
- const trashDmsType = await models.DmsType.findOne({where: {code: 'trash'}});
const dms = await models.Dms.findById(id);
+ const trashDmsType = await models.DmsType.findOne({
+ where: {code: 'trash'}
+ });
const hasWriteRole = await models.DmsType.hasWriteRole(ctx, dms.dmsTypeFk);
if (!hasWriteRole)
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 0b546f313..e9654d062 100644
--- a/db/dump/fixtures.sql
+++ b/db/dump/fixtures.sql
@@ -1950,11 +1950,14 @@ INSERT INTO `vn`.`thermograph`(`id`, `model`)
VALUES
('TMM190901395', 'TEMPMATE'),
('TL.BBA85422', 'TL30'),
- ('TZ1905012010', 'DISPOSABLE');
+ ('TZ1905012010', 'DISPOSABLE'),
+ ('138350-0', 'DISPOSABLE');
INSERT INTO `vn`.`travelThermograph`(`thermographFk`, `created`, `warehouseFk`, `travelFk`, `temperature`, `result`, `dmsFk`)
VALUES
- ('TMM190901395', CURDATE(), 1, 1, 'WARM', 'Ok', NULL),
- ('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);
\ No newline at end of file
+ ('TMM190901395', CURDATE(), 1, 1, 'WARM', 'Ok', NULL),
+ ('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', DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, 1, 'WARM', NULL, 5),
+ ('138350-0', CURDATE(), 1, NULL, 'COOL', NULL, NULL);
\ 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/claim/front/action/index.spec.js b/modules/claim/front/action/index.spec.js
index 0d10957e7..539d2e8ef 100644
--- a/modules/claim/front/action/index.spec.js
+++ b/modules/claim/front/action/index.spec.js
@@ -206,9 +206,9 @@ describe('claim', () => {
return resolve({id: freightPickUpPrice});
}));
controller.onUpdateGreugeResponse('accept').then(res => {
- console.log('asdas');
+
}).catch(error => {
- console.log('errorrrr!!');
+
});
$httpBackend.flush();
diff --git a/modules/travel/back/methods/travel-thermograph/allowedContentTypes.js b/modules/travel/back/methods/travel-thermograph/allowedContentTypes.js
new file mode 100644
index 000000000..2f5183f92
--- /dev/null
+++ b/modules/travel/back/methods/travel-thermograph/allowedContentTypes.js
@@ -0,0 +1,23 @@
+module.exports = Self => {
+ Self.remoteMethodCtx('allowedContentTypes', {
+ description: 'Returns a list of allowed contentTypes',
+ accessType: 'READ',
+ returns: {
+ type: ['Object'],
+ root: true
+ },
+ http: {
+ path: `/allowedContentTypes`,
+ verb: 'GET'
+ }
+ });
+
+ Self.allowedContentTypes = async() => {
+ const storageConnector = Self.app.dataSources.storage.connector;
+ const allowedContentTypes = storageConnector.allowedContentTypes;
+ const modelAllowedContentTypes = Self.definition.settings.allowedContentTypes;
+
+ return modelAllowedContentTypes || allowedContentTypes;
+ };
+};
+
diff --git a/modules/travel/back/methods/travel/createThermograph.js b/modules/travel/back/methods/travel/createThermograph.js
new file mode 100644
index 000000000..cbf0678d1
--- /dev/null
+++ b/modules/travel/back/methods/travel/createThermograph.js
@@ -0,0 +1,84 @@
+const UserError = require('vn-loopback/util/user-error');
+
+module.exports = Self => {
+ Self.remoteMethodCtx('createThermograph', {
+ description: 'Upload and attach a document',
+ accessType: 'WRITE',
+ accepts: [{
+ arg: 'id',
+ type: 'Number',
+ description: 'The travel id',
+ http: {source: 'path'}
+ }, {
+ arg: 'thermographId',
+ type: 'String',
+ description: 'The thermograph id',
+ required: true
+ }, {
+ arg: 'warehouseId',
+ type: 'Number',
+ description: 'The warehouse id',
+ required: true
+ }, {
+ arg: 'companyId',
+ type: 'Number',
+ description: 'The company id',
+ required: true
+ }, {
+ arg: 'dmsTypeId',
+ type: 'Number',
+ description: 'The dms type id',
+ required: true
+ }, {
+ arg: 'reference',
+ type: 'String',
+ required: true
+ }, {
+ arg: 'description',
+ type: 'String',
+ required: true
+ }],
+ returns: {
+ type: 'Object',
+ root: true
+ },
+ http: {
+ path: `/:id/createThermograph`,
+ verb: 'POST'
+ }
+ });
+
+ Self.createThermograph = async(ctx, id, thermographId) => {
+ const models = Self.app.models;
+ const tx = await Self.beginTransaction({});
+
+ try {
+ const options = {transaction: tx};
+
+ const travelThermograph = await models.TravelThermograph.findOne({
+ where: {
+ thermographFk: thermographId,
+ travelFk: null
+ }
+ }, options);
+
+ if (!travelThermograph)
+ throw new UserError('No valid travel thermograph found');
+
+ const uploadedFiles = await models.Dms.uploadFile(ctx, options);
+ const firstDms = uploadedFiles[0];
+
+ await travelThermograph.updateAttributes({
+ dmsFk: firstDms.id,
+ travelFk: id
+ }, options);
+
+ await tx.commit();
+
+ return travelThermograph;
+ } catch (err) {
+ await tx.rollback();
+ throw err;
+ }
+ };
+};
diff --git a/modules/travel/back/methods/travel/deleteThermograph.js b/modules/travel/back/methods/travel/deleteThermograph.js
new file mode 100644
index 000000000..ba541c560
--- /dev/null
+++ b/modules/travel/back/methods/travel/deleteThermograph.js
@@ -0,0 +1,53 @@
+
+module.exports = Self => {
+ Self.remoteMethodCtx('deleteThermograph', {
+ description: 'Deletes a travel thermograph',
+ accessType: 'WRITE',
+ accepts: {
+ arg: 'id',
+ type: 'Number',
+ description: 'The thermograph id',
+ required: true
+ },
+ returns: {
+ type: 'object',
+ root: true
+ },
+ http: {
+ path: '/deleteThermograph',
+ verb: 'DELETE'
+ }
+ });
+
+ Self.deleteThermograph = async(ctx, id) => {
+ const models = Self.app.models;
+ const userId = ctx.req.accessToken.userId;
+ const travelThermograph = await models.TravelThermograph.findById(id);
+
+ await models.Dms.removeFile(ctx, travelThermograph.dmsFk);
+ await Self.rawSql(`
+ UPDATE travelThermograph
+ SET travelFk = NULL, dmsFk = NULL
+ WHERE id = ?`, [id]);
+
+ const oldInstance = {
+ travelFk: travelThermograph.travelFk,
+ dmsFk: travelThermograph.dmsFk
+ };
+
+ await models.TravelLog.create({
+ originFk: travelThermograph.travelFk,
+ userFk: userId,
+ action: 'delete',
+ changedModel: 'TravelThermograph',
+ changedModelId: id,
+ oldInstance: oldInstance,
+ newInstance: {}
+ });
+
+ travelThermograph.travelFk = null;
+ travelThermograph.dmsFk = null;
+
+ return travelThermograph;
+ };
+};
diff --git a/modules/travel/back/methods/travel/specs/createThermograph.spec.js b/modules/travel/back/methods/travel/specs/createThermograph.spec.js
new file mode 100644
index 000000000..b85dcca04
--- /dev/null
+++ b/modules/travel/back/methods/travel/specs/createThermograph.spec.js
@@ -0,0 +1,50 @@
+const app = require('vn-loopback/server/server');
+
+describe('Travel createThermograph()', () => {
+ const models = app.models;
+ const travelId = 3;
+ const currentUserId = 102;
+ const thermographId = '138350-0';
+ const ctx = {req: {accessToken: {userId: currentUserId}}, args: {dmsTypeId: 1}};
+ let travelThermographBefore;
+
+ afterAll(async done => {
+ await app.models.TravelThermograph.rawSql(`
+ UPDATE travelThermograph
+ SET travelFk = NULL, dmsFk = NULL
+ WHERE id = ?`, [travelThermographBefore.id]);
+
+ done();
+ });
+
+ it(`should set the travelFk and dmsFk properties to the travel thermograph`, async() => {
+ spyOn(app.models.Dms, 'uploadFile').and.returnValue([{id: 5}]);
+
+ travelThermographBefore = await models.TravelThermograph.findOne({
+ where: {
+ thermographFk: thermographId,
+ travelFk: null
+ }
+ });
+
+ await models.Travel.createThermograph(ctx, travelId, thermographId);
+
+ const travelThermographAfter = await models.TravelThermograph.findOne({
+ where: {
+ thermographFk: thermographId,
+ travelFk: travelId
+ }
+ });
+
+ expect(app.models.Dms.uploadFile).toHaveBeenCalledWith(ctx, jasmine.any(Object));
+
+ expect(travelThermographBefore).toBeDefined();
+ expect(travelThermographBefore.thermographFk).toEqual(thermographId);
+ expect(travelThermographBefore.travelFk).toBeNull();
+ expect(travelThermographAfter).toBeDefined();
+
+ expect(travelThermographAfter.thermographFk).toEqual(thermographId);
+ expect(travelThermographAfter.travelFk).toEqual(travelId);
+ expect(travelThermographAfter.dmsFk).toEqual(5);
+ });
+});
diff --git a/modules/travel/back/methods/travel/specs/deleteThermograph.spec.js b/modules/travel/back/methods/travel/specs/deleteThermograph.spec.js
new file mode 100644
index 000000000..843fa046c
--- /dev/null
+++ b/modules/travel/back/methods/travel/specs/deleteThermograph.spec.js
@@ -0,0 +1,56 @@
+const app = require('vn-loopback/server/server');
+
+describe('Travel deleteThermograph()', () => {
+ const models = app.models;
+ const travelId = 1;
+ const currentUserId = 102;
+ const thermographId = 'TZ1905012010';
+ const travelThermographId = 4;
+ const dmsId = 5;
+ const ctx = {req: {accessToken: {userId: currentUserId}}};
+ let travelThermographBefore;
+
+ afterAll(async done => {
+ await app.models.TravelThermograph.rawSql(`
+ UPDATE travelThermograph
+ SET travelFk = ?, dmsFk = ?
+ WHERE id = ?`, [
+ travelThermographBefore.travelFk,
+ travelThermographBefore.dmsFk,
+ travelThermographBefore.id
+ ]);
+
+ done();
+ });
+
+ it(`should set the travelFk and dmsFk properties to null for travel thermograph removal`, async() => {
+ spyOn(app.models.Dms, 'removeFile').and.returnValue([{id: 5}]);
+
+ travelThermographBefore = await models.TravelThermograph.findOne({
+ where: {
+ thermographFk: thermographId,
+ travelFk: travelId
+ }
+ });
+
+ await models.Travel.deleteThermograph(ctx, travelThermographId);
+
+ const travelThermographAfter = await models.TravelThermograph.findOne({
+ where: {
+ thermographFk: thermographId,
+ travelFk: null
+ }
+ });
+
+ expect(app.models.Dms.removeFile).toHaveBeenCalledWith(ctx, dmsId);
+
+ expect(travelThermographBefore).toBeDefined();
+ expect(travelThermographBefore.thermographFk).toEqual(thermographId);
+ expect(travelThermographBefore.travelFk).toEqual(travelId);
+ expect(travelThermographBefore.dmsFk).toEqual(5);
+
+ expect(travelThermographAfter).toBeDefined();
+ expect(travelThermographAfter.thermographFk).toEqual(thermographId);
+ expect(travelThermographAfter.travelFk).toBeNull();
+ });
+});
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.js b/modules/travel/back/models/travel-thermograph.js
new file mode 100644
index 000000000..0d70edd7e
--- /dev/null
+++ b/modules/travel/back/models/travel-thermograph.js
@@ -0,0 +1,4 @@
+module.exports = Self => {
+ require('../methods/travel-thermograph/allowedContentTypes')(Self);
+};
+
diff --git a/modules/travel/back/models/travel-thermograph.json b/modules/travel/back/models/travel-thermograph.json
index 18e632d02..b8f7fa41a 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": {
@@ -10,15 +12,13 @@
}
},
"properties": {
- "thermographFk": {
- "type": "String",
- "id": 1,
- "description": "Identifier"
+ "id": {
+ "type": "Number",
+ "description": "Identifier",
+ "id": true
},
"created": {
- "type": "Date",
- "id": 2,
- "description": "Identifier"
+ "type": "Date"
},
"temperature": {
"type": "String"
diff --git a/modules/travel/back/models/travel.js b/modules/travel/back/models/travel.js
index 5fa55a366..895de7af1 100644
--- a/modules/travel/back/models/travel.js
+++ b/modules/travel/back/models/travel.js
@@ -2,4 +2,6 @@ module.exports = Self => {
require('../methods/travel/getTravel')(Self);
require('../methods/travel/getEntries')(Self);
require('../methods/travel/filter')(Self);
+ require('../methods/travel/createThermograph')(Self);
+ require('../methods/travel/deleteThermograph')(Self);
};
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/index.js b/modules/travel/front/index.js
index 4bf935a8c..1f5346e98 100644
--- a/modules/travel/front/index.js
+++ b/modules/travel/front/index.js
@@ -9,5 +9,6 @@ import './summary';
import './basic-data';
import './log';
import './create';
-import './thermograph';
+import './thermograph/index/';
+import './thermograph/create/';
diff --git a/modules/travel/front/locale/es.yml b/modules/travel/front/locale/es.yml
index 31e4e452b..931f79ab8 100644
--- a/modules/travel/front/locale/es.yml
+++ b/modules/travel/front/locale/es.yml
@@ -16,4 +16,4 @@ New travel: Nuevo envío
# Sections
Travels: Envíos
Log: Historial
-Thermographs: Termómetros
\ No newline at end of file
+Thermographs: Termógrafos
\ No newline at end of file
diff --git a/modules/travel/front/routes.json b/modules/travel/front/routes.json
index d7d5b52df..fcbe5b92f 100644
--- a/modules/travel/front/routes.json
+++ b/modules/travel/front/routes.json
@@ -11,7 +11,7 @@
"card": [
{"state": "travel.card.basicData", "icon": "settings"},
{"state": "travel.card.log", "icon": "history"},
- {"state": "travel.card.thermograph", "icon": "icon-thermometer"}
+ {"state": "travel.card.thermograph.index", "icon": "icon-thermometer"}
]
},
"routes": [
@@ -59,14 +59,28 @@
"component": "vn-travel-create",
"description": "New travel"
}, {
- "url" : "/thermograph",
+ "url": "/thermograph",
"state": "travel.card.thermograph",
- "component": "vn-travel-thermograph",
+ "abstract": true,
+ "component": "ui-view"
+ }, {
+ "url" : "/index",
+ "state": "travel.card.thermograph.index",
+ "component": "vn-travel-thermograph-index",
"description": "Thermographs",
"params": {
"travel": "$ctrl.travel"
},
"acl": ["buyer"]
+ }, {
+ "url" : "/create",
+ "state": "travel.card.thermograph.create",
+ "component": "vn-travel-thermograph-create",
+ "description": "Add thermograph",
+ "params": {
+ "travel": "$ctrl.travel"
+ },
+ "acl": ["buyer"]
}
]
}
\ No newline at end of file
diff --git a/modules/travel/front/thermograph/create/index.html b/modules/travel/front/thermograph/create/index.html
new file mode 100644
index 000000000..02ef54264
--- /dev/null
+++ b/modules/travel/front/thermograph/create/index.html
@@ -0,0 +1,79 @@
+