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',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'Number',
|
type: 'String',
|
||||||
description: 'The ticket id',
|
description: 'The thermograph id',
|
||||||
http: {source: 'path'}
|
http: {source: 'path'}
|
||||||
|
}, {
|
||||||
|
arg: 'travelId',
|
||||||
|
type: 'Number',
|
||||||
|
description: 'The travel id',
|
||||||
|
required: true
|
||||||
}, {
|
}, {
|
||||||
arg: 'warehouseId',
|
arg: 'warehouseId',
|
||||||
type: 'Number',
|
type: 'Number',
|
||||||
|
@ -30,11 +35,6 @@ module.exports = Self => {
|
||||||
arg: 'description',
|
arg: 'description',
|
||||||
type: 'String',
|
type: 'String',
|
||||||
required: true
|
required: true
|
||||||
}, {
|
|
||||||
arg: 'hasFile',
|
|
||||||
type: 'Boolean',
|
|
||||||
description: 'True if has an attached file',
|
|
||||||
required: true
|
|
||||||
}],
|
}],
|
||||||
returns: {
|
returns: {
|
||||||
type: 'Object',
|
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 models = Self.app.models;
|
||||||
const promises = [];
|
|
||||||
const tx = await Self.beginTransaction({});
|
const tx = await Self.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const options = {transaction: tx};
|
||||||
|
|
||||||
const uploadedFiles = await models.Dms.uploadFile(ctx, options);
|
const uploadedFiles = await models.Dms.uploadFile(ctx, options);
|
||||||
uploadedFiles.forEach(dms => {
|
const firstDms = uploadedFiles[0];
|
||||||
const newTicketDms = models.TicketDms.create({
|
|
||||||
ticketFk: id,
|
|
||||||
dmsFk: dms.id
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
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();
|
await tx.commit();
|
||||||
|
|
||||||
return resolvedPromises;
|
return travelThermograph;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
await tx.rollback();
|
await tx.rollback();
|
||||||
throw err;
|
throw err;
|
||||||
|
|
|
@ -9,9 +9,9 @@ class Controller {
|
||||||
this.vnApp = vnApp;
|
this.vnApp = vnApp;
|
||||||
this.vnConfig = vnConfig;
|
this.vnConfig = vnConfig;
|
||||||
this.dms = {
|
this.dms = {
|
||||||
files: [],
|
travelId: $state.params.id,
|
||||||
hasFile: false,
|
hasFileAttached: false,
|
||||||
hasFileAttached: false
|
files: []
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue