allowContentTypes and removeFile refactors
This commit is contained in:
parent
740cc79bc0
commit
c1f457c263
|
@ -3,7 +3,7 @@ module.exports = Self => {
|
||||||
description: 'Returns a list of allowed contentTypes',
|
description: 'Returns a list of allowed contentTypes',
|
||||||
accessType: 'READ',
|
accessType: 'READ',
|
||||||
returns: {
|
returns: {
|
||||||
type: ['Object'],
|
type: ['object'],
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
|
|
|
@ -4,12 +4,12 @@ module.exports = Self => {
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: {
|
accepts: {
|
||||||
arg: 'id',
|
arg: 'id',
|
||||||
type: 'Number',
|
type: 'number',
|
||||||
description: 'The document id',
|
description: 'The document id',
|
||||||
http: {source: 'path'}
|
http: {source: 'path'}
|
||||||
},
|
},
|
||||||
returns: {
|
returns: {
|
||||||
type: 'Object',
|
type: 'object',
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
|
@ -18,16 +18,36 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.removeFile = async(ctx, id) => {
|
Self.removeFile = 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const targetClaimDms = await models.ClaimDms.findById(id);
|
const targetClaimDms = await models.ClaimDms.findById(id, null, myOptions);
|
||||||
const targetDms = await models.Dms.findById(targetClaimDms.dmsFk);
|
const targetDms = await models.Dms.findById(targetClaimDms.dmsFk, null, myOptions);
|
||||||
const trashDmsType = await models.DmsType.findOne({where: {code: 'trash'}});
|
const trashDmsType = await models.DmsType.findOne({where: {code: 'trash'}}, myOptions);
|
||||||
|
|
||||||
await models.Dms.removeFile(ctx, targetClaimDms.dmsFk);
|
await models.Dms.removeFile(ctx, targetClaimDms.dmsFk, myOptions);
|
||||||
await targetClaimDms.destroy();
|
await targetClaimDms.destroy(myOptions);
|
||||||
|
|
||||||
return targetDms.updateAttribute('dmsTypeFk', trashDmsType.id);
|
await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions);
|
||||||
|
|
||||||
|
if (tx) await tx.commit();
|
||||||
|
|
||||||
|
return targetDms;
|
||||||
|
} catch (e) {
|
||||||
|
if (tx) await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue