added travel thermograph create & remove methods
gitea/salix/1982-travel_add_thermograph There was a failure building this commit
Details
gitea/salix/1982-travel_add_thermograph There was a failure building this commit
Details
This commit is contained in:
parent
5e4ab8b128
commit
f0b4c26aea
|
@ -22,8 +22,10 @@ module.exports = Self => {
|
||||||
|
|
||||||
Self.removeFile = async(ctx, id) => {
|
Self.removeFile = async(ctx, id) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const trashDmsType = await models.DmsType.findOne({where: {code: 'trash'}});
|
|
||||||
const dms = await models.Dms.findById(id);
|
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);
|
const hasWriteRole = await models.DmsType.hasWriteRole(ctx, dms.dmsTypeFk);
|
||||||
if (!hasWriteRole)
|
if (!hasWriteRole)
|
||||||
|
|
|
@ -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', DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 2, 2, 'COOL', 'Ok', NULL),
|
||||||
('TL.BBA85422', CURDATE(), 2, 1, 'COOL', 'can not read the temperature', NULL),
|
('TL.BBA85422', CURDATE(), 2, 1, 'COOL', 'can not read the temperature', NULL),
|
||||||
('TZ1905012010', CURDATE(), 1, 1, 'WARM', 'Temperature in range', 5),
|
('TZ1905012010', CURDATE(), 1, 1, 'WARM', 'Temperature in range', 5),
|
||||||
('138350-0', DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, NULL, 'WARM', NULL, 5),
|
('138350-0', DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, 1, 'WARM', NULL, 5),
|
||||||
('138350-0', CURDATE(), 1, 1, 'WARM', 'Ok', 5);
|
('138350-0', CURDATE(), 1, NULL, 'COOL', NULL, NULL);
|
|
@ -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;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1,16 +1,16 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('uploadFile', {
|
Self.remoteMethodCtx('createThermograph', {
|
||||||
description: 'Upload and attach a document',
|
description: 'Upload and attach a document',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'String',
|
|
||||||
description: 'The thermograph id',
|
|
||||||
http: {source: 'path'}
|
|
||||||
}, {
|
|
||||||
arg: 'travelId',
|
|
||||||
type: 'Number',
|
type: 'Number',
|
||||||
description: 'The travel id',
|
description: 'The travel id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
}, {
|
||||||
|
arg: 'thermographId',
|
||||||
|
type: 'String',
|
||||||
|
description: 'The thermograph id',
|
||||||
required: true
|
required: true
|
||||||
}, {
|
}, {
|
||||||
arg: 'warehouseId',
|
arg: 'warehouseId',
|
||||||
|
@ -41,12 +41,12 @@ module.exports = Self => {
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
path: `/:id/uploadFile`,
|
path: `/:id/createThermograph`,
|
||||||
verb: 'POST'
|
verb: 'POST'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.uploadFile = async(ctx, thermographId, travelId) => {
|
Self.createThermograph = async(ctx, id, thermographId) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const tx = await Self.beginTransaction({});
|
const tx = await Self.beginTransaction({});
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ module.exports = Self => {
|
||||||
|
|
||||||
await travelThermograph.updateAttributes({
|
await travelThermograph.updateAttributes({
|
||||||
dmsFk: firstDms.id,
|
dmsFk: firstDms.id,
|
||||||
travelFk: travelId
|
travelFk: id
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
await tx.commit();
|
await tx.commit();
|
|
@ -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;
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,3 +0,0 @@
|
||||||
module.exports = Self => {
|
|
||||||
require('../methods/travel-thermograph/uploadFile')(Self);
|
|
||||||
};
|
|
|
@ -12,14 +12,13 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"properties": {
|
"properties": {
|
||||||
"thermographFk": {
|
"id": {
|
||||||
"type": "String",
|
"type": "Number",
|
||||||
"description": "Identifier",
|
"description": "Identifier",
|
||||||
"id": true
|
"id": true
|
||||||
},
|
},
|
||||||
"created": {
|
"created": {
|
||||||
"type": "Date",
|
"type": "Date"
|
||||||
"description": "Identifier"
|
|
||||||
},
|
},
|
||||||
"temperature": {
|
"temperature": {
|
||||||
"type": "String"
|
"type": "String"
|
||||||
|
|
|
@ -2,4 +2,6 @@ module.exports = Self => {
|
||||||
require('../methods/travel/getTravel')(Self);
|
require('../methods/travel/getTravel')(Self);
|
||||||
require('../methods/travel/getEntries')(Self);
|
require('../methods/travel/getEntries')(Self);
|
||||||
require('../methods/travel/filter')(Self);
|
require('../methods/travel/filter')(Self);
|
||||||
|
require('../methods/travel/createThermograph')(Self);
|
||||||
|
require('../methods/travel/deleteThermograph')(Self);
|
||||||
};
|
};
|
||||||
|
|
|
@ -9,7 +9,6 @@ class Controller {
|
||||||
this.vnApp = vnApp;
|
this.vnApp = vnApp;
|
||||||
this.vnConfig = vnConfig;
|
this.vnConfig = vnConfig;
|
||||||
this.dms = {
|
this.dms = {
|
||||||
travelId: $state.params.id,
|
|
||||||
hasFileAttached: false,
|
hasFileAttached: false,
|
||||||
files: []
|
files: []
|
||||||
};
|
};
|
||||||
|
@ -65,7 +64,7 @@ class Controller {
|
||||||
}
|
}
|
||||||
|
|
||||||
onSubmit() {
|
onSubmit() {
|
||||||
const query = `TravelThermographs/${this.dms.thermographId}/uploadFile`;
|
const query = `Travels/${this.travel.id}/createThermograph`;
|
||||||
const options = {
|
const options = {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: query,
|
url: query,
|
||||||
|
|
|
@ -28,6 +28,15 @@
|
||||||
<vn-td expand>{{thermograph.result}}</vn-td>
|
<vn-td expand>{{thermograph.result}}</vn-td>
|
||||||
<vn-td>{{thermograph.warehouse.name}}</vn-td>
|
<vn-td>{{thermograph.warehouse.name}}</vn-td>
|
||||||
<vn-td>{{thermograph.created | date: 'dd/MM/yyyy'}}</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-td shrink>
|
||||||
<vn-icon-button
|
<vn-icon-button
|
||||||
icon="delete"
|
icon="delete"
|
||||||
|
@ -45,8 +54,8 @@
|
||||||
|
|
||||||
<vn-confirm
|
<vn-confirm
|
||||||
vn-id="confirm"
|
vn-id="confirm"
|
||||||
question="Delete thermograph from travel?"
|
question="Are you sure you want to remove the thermograph?"
|
||||||
on-response="$ctrl.removeThermographFromTravel($response)">
|
on-accept="$ctrl.deleteThermograph()">
|
||||||
</vn-confirm>
|
</vn-confirm>
|
||||||
|
|
||||||
<a
|
<a
|
||||||
|
|
|
@ -3,8 +3,9 @@ import './style.scss';
|
||||||
import Component from 'core/lib/component';
|
import Component from 'core/lib/component';
|
||||||
|
|
||||||
class Controller extends Component {
|
class Controller extends Component {
|
||||||
constructor($element, $) {
|
constructor($element, $, vnToken) {
|
||||||
super($element, $);
|
super($element, $);
|
||||||
|
this.accessToken = vnToken.token;
|
||||||
this.filter = {
|
this.filter = {
|
||||||
include:
|
include:
|
||||||
{relation: 'warehouse',
|
{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', {
|
ngModule.component('vnTravelThermographIndex', {
|
||||||
template: require('./index.html'),
|
template: require('./index.html'),
|
||||||
controller: Controller,
|
controller: Controller,
|
||||||
|
|
|
@ -3,7 +3,7 @@ Temperature: Temperatura
|
||||||
State: Estado
|
State: Estado
|
||||||
Destination: Destino
|
Destination: Destino
|
||||||
Created: Creado
|
Created: Creado
|
||||||
Remove thermograph: Eliminar termómetro
|
Remove thermograph: Eliminar termógrafo
|
||||||
Upload file: Subir fichero
|
Upload file: Subir fichero
|
||||||
Edit file: Editar fichero
|
Edit file: Editar fichero
|
||||||
Upload: Subir
|
Upload: Subir
|
||||||
|
@ -12,3 +12,6 @@ FileDescription: Travel id {{travelId}}
|
||||||
ContentTypesInfo: 'Tipos de archivo permitidos: {{allowedContentTypes}}'
|
ContentTypesInfo: 'Tipos de archivo permitidos: {{allowedContentTypes}}'
|
||||||
Are you sure you want to continue?: ¿Seguro que quieres continuar?
|
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?
|
Loading…
Reference in New Issue