uploadFile refactor
This commit is contained in:
parent
de2a17e840
commit
740cc79bc0
|
@ -4,40 +4,46 @@ module.exports = Self => {
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'Number',
|
type: 'number',
|
||||||
description: 'The claim id',
|
description: 'The claim id',
|
||||||
http: {source: 'path'}
|
http: {source: 'path'}
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
arg: 'warehouseId',
|
arg: 'warehouseId',
|
||||||
type: 'Number',
|
type: 'number',
|
||||||
description: 'The warehouse id',
|
description: 'The warehouse id',
|
||||||
required: true
|
required: true
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
arg: 'companyId',
|
arg: 'companyId',
|
||||||
type: 'Number',
|
type: 'number',
|
||||||
description: 'The company id',
|
description: 'The company id',
|
||||||
required: true
|
required: true
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
arg: 'dmsTypeId',
|
arg: 'dmsTypeId',
|
||||||
type: 'Number',
|
type: 'number',
|
||||||
description: 'The dms type id',
|
description: 'The dms type id',
|
||||||
required: true
|
required: true
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
arg: 'reference',
|
arg: 'reference',
|
||||||
type: 'String',
|
type: 'string',
|
||||||
required: true
|
required: true
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
arg: 'description',
|
arg: 'description',
|
||||||
type: 'String',
|
type: 'string',
|
||||||
required: true
|
required: true
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
arg: 'hasFile',
|
arg: 'hasFile',
|
||||||
type: 'Boolean',
|
type: 'boolean',
|
||||||
description: 'True if has an attached file',
|
description: 'True if has an attached file',
|
||||||
required: true
|
required: true
|
||||||
}],
|
}],
|
||||||
returns: {
|
returns: {
|
||||||
type: 'Object',
|
type: 'object',
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
|
@ -46,20 +52,27 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.uploadFile = async(ctx, id) => {
|
Self.uploadFile = async(ctx, id, options) => {
|
||||||
|
let tx;
|
||||||
|
let myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const promises = [];
|
const promises = [];
|
||||||
const tx = await Self.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const options = {transaction: tx};
|
const uploadedFiles = await models.Dms.uploadFile(ctx, myOptions);
|
||||||
|
|
||||||
const uploadedFiles = await models.Dms.uploadFile(ctx, options);
|
|
||||||
uploadedFiles.forEach(dms => {
|
uploadedFiles.forEach(dms => {
|
||||||
const newClaimDms = models.ClaimDms.create({
|
const newClaimDms = models.ClaimDms.create({
|
||||||
claimFk: id,
|
claimFk: id,
|
||||||
dmsFk: dms.id
|
dmsFk: dms.id
|
||||||
}, options);
|
}, myOptions);
|
||||||
|
|
||||||
promises.push(newClaimDms);
|
promises.push(newClaimDms);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue