uploadFile args
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
4002b51565
commit
65a227db9e
|
@ -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;
|
||||
|
|
|
@ -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: []
|
||||
};
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue