From 65a227db9e6339bcf636fd17c719964f9b51b2ee Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Fri, 17 Jan 2020 09:23:32 +0100 Subject: [PATCH] uploadFile args --- .../methods/travel-thermograph/uploadFile.js | 38 ++++++++++--------- .../travel/front/thermograph/create/index.js | 6 +-- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/modules/travel/back/methods/travel-thermograph/uploadFile.js b/modules/travel/back/methods/travel-thermograph/uploadFile.js index e5ea465cb..0cff11204 100644 --- a/modules/travel/back/methods/travel-thermograph/uploadFile.js +++ b/modules/travel/back/methods/travel-thermograph/uploadFile.js @@ -4,9 +4,14 @@ module.exports = Self => { accessType: 'WRITE', accepts: [{ arg: 'id', - type: 'Number', - description: 'The ticket id', + type: 'String', + description: 'The thermograph id', http: {source: 'path'} + }, { + arg: 'travelId', + type: 'Number', + description: 'The travel id', + required: true }, { arg: 'warehouseId', type: 'Number', @@ -30,11 +35,6 @@ module.exports = Self => { arg: 'description', type: 'String', required: true - }, { - arg: 'hasFile', - type: 'Boolean', - description: 'True if has an attached file', - required: true }], returns: { type: 'Object', @@ -46,28 +46,30 @@ module.exports = Self => { } }); - Self.uploadFile = async(ctx, id) => { + Self.uploadFile = async(ctx, thermograpId, travelId) => { const models = Self.app.models; - const promises = []; const tx = await Self.beginTransaction({}); try { const options = {transaction: tx}; - const uploadedFiles = await models.Dms.uploadFile(ctx, options); - uploadedFiles.forEach(dms => { - const newTicketDms = models.TicketDms.create({ - ticketFk: id, - dmsFk: dms.id - }, options); + const firstDms = uploadedFiles[0]; - promises.push(newTicketDms); + const travelThermograph = await models.TravelThermograph.findOne({ + where: { + thermographFk: thermograpId, + travelFk: null + } + }, options); + + await travelThermograph.updateAttributes({ + dmsFk: firstDms.id, + travelFk: travelId }); - const resolvedPromises = await Promise.all(promises); await tx.commit(); - return resolvedPromises; + return travelThermograph; } catch (err) { await tx.rollback(); throw err; diff --git a/modules/travel/front/thermograph/create/index.js b/modules/travel/front/thermograph/create/index.js index 2f3f3f807..b12bf47ff 100644 --- a/modules/travel/front/thermograph/create/index.js +++ b/modules/travel/front/thermograph/create/index.js @@ -9,9 +9,9 @@ class Controller { this.vnApp = vnApp; this.vnConfig = vnConfig; this.dms = { - files: [], - hasFile: false, - hasFileAttached: false + travelId: $state.params.id, + hasFileAttached: false, + files: [] }; }