added travel thermograph create & remove methods
gitea/salix/1982-travel_add_thermograph There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2020-01-21 12:21:53 +01:00
parent 5e4ab8b128
commit f0b4c26aea
12 changed files with 109 additions and 87 deletions

View File

@ -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)

View File

@ -1959,5 +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', DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, NULL, 'WARM', NULL, 5),
('138350-0', CURDATE(), 1, 1, 'WARM', 'Ok', 5);
('138350-0', DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, 1, 'WARM', NULL, 5),
('138350-0', CURDATE(), 1, NULL, 'COOL', NULL, NULL);

View File

@ -1,61 +0,0 @@
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;
}
};
};

View File

@ -1,16 +1,16 @@
module.exports = Self => {
Self.remoteMethodCtx('uploadFile', {
Self.remoteMethodCtx('createThermograph', {
description: 'Upload and attach a document',
accessType: 'WRITE',
accepts: [{
arg: 'id',
type: 'String',
description: 'The thermograph id',
http: {source: 'path'}
}, {
arg: 'travelId',
type: 'Number',
description: 'The travel id',
http: {source: 'path'}
}, {
arg: 'thermographId',
type: 'String',
description: 'The thermograph id',
required: true
}, {
arg: 'warehouseId',
@ -41,12 +41,12 @@ module.exports = Self => {
root: true
},
http: {
path: `/:id/uploadFile`,
path: `/:id/createThermograph`,
verb: 'POST'
}
});
Self.uploadFile = async(ctx, thermographId, travelId) => {
Self.createThermograph = async(ctx, id, thermographId) => {
const models = Self.app.models;
const tx = await Self.beginTransaction({});
@ -64,7 +64,7 @@ module.exports = Self => {
await travelThermograph.updateAttributes({
dmsFk: firstDms.id,
travelFk: travelId
travelFk: id
}, options);
await tx.commit();

View File

@ -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;
};
};

View File

@ -1,3 +0,0 @@
module.exports = Self => {
require('../methods/travel-thermograph/uploadFile')(Self);
};

View File

@ -12,14 +12,13 @@
}
},
"properties": {
"thermographFk": {
"type": "String",
"id": {
"type": "Number",
"description": "Identifier",
"id": true
},
"created": {
"type": "Date",
"description": "Identifier"
"type": "Date"
},
"temperature": {
"type": "String"

View File

@ -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);
};

View File

@ -9,7 +9,6 @@ class Controller {
this.vnApp = vnApp;
this.vnConfig = vnConfig;
this.dms = {
travelId: $state.params.id,
hasFileAttached: false,
files: []
};
@ -65,7 +64,7 @@ class Controller {
}
onSubmit() {
const query = `TravelThermographs/${this.dms.thermographId}/uploadFile`;
const query = `Travels/${this.travel.id}/createThermograph`;
const options = {
method: 'POST',
url: query,

View File

@ -28,6 +28,15 @@
<vn-td expand>{{thermograph.result}}</vn-td>
<vn-td>{{thermograph.warehouse.name}}</vn-td>
<vn-td>{{thermograph.created | date: 'dd/MM/yyyy'}}</vn-td>
<vn-td shrink>
<a target="_blank"
href="api/dms/{{::thermograph.dmsFk}}/downloadFile?access_token={{::$ctrl.accessToken}}">
<vn-icon-button
icon="cloud_download"
title="{{'Download file' | translate}}">
</vn-icon-button>
</a>
</vn-td>
<vn-td shrink>
<vn-icon-button
icon="delete"
@ -45,8 +54,8 @@
<vn-confirm
vn-id="confirm"
question="Delete thermograph from travel?"
on-response="$ctrl.removeThermographFromTravel($response)">
question="Are you sure you want to remove the thermograph?"
on-accept="$ctrl.deleteThermograph()">
</vn-confirm>
<a

View File

@ -3,8 +3,9 @@ import './style.scss';
import Component from 'core/lib/component';
class Controller extends Component {
constructor($element, $) {
constructor($element, $, vnToken) {
super($element, $);
this.accessToken = vnToken.token;
this.filter = {
include:
{relation: 'warehouse',
@ -14,8 +15,26 @@ class Controller extends Component {
}
};
}
showDeleteConfirm(index) {
this.thermographIndex = index;
this.$.confirm.show();
}
deleteThermograph() {
const data = this.travelThermographs;
const thermographId = data[this.thermographIndex].id;
const query = `Travels/deleteThermograph?id=${thermographId}`;
this.$http.delete(query).then(() => {
this.vnApp.showSuccess(this.$translate.instant('Thermograph deleted'));
this.$.model.remove(this.thermographIndex);
this.thermographIndex = null;
});
}
}
Controller.$inject = ['$element', '$scope', 'vnToken'];
ngModule.component('vnTravelThermographIndex', {
template: require('./index.html'),
controller: Controller,

View File

@ -3,7 +3,7 @@ Temperature: Temperatura
State: Estado
Destination: Destino
Created: Creado
Remove thermograph: Eliminar termómetro
Remove thermograph: Eliminar termógrafo
Upload file: Subir fichero
Edit file: Editar fichero
Upload: Subir
@ -11,4 +11,7 @@ File: Fichero
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
Add thermograph: Añadir termógrafo
Thermograph deleted: Termógrafo eliminado
Thermograph: Termógrafo
Are you sure you want to remove the thermograph?: ¿Seguro que quieres quitar el termógrafo?