2019-07-30 06:51:38 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethodCtx('removeFile', {
|
2019-11-22 12:46:38 +00:00
|
|
|
description: 'Removes a claim document',
|
2019-07-30 06:51:38 +00:00
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: {
|
|
|
|
arg: 'id',
|
|
|
|
type: 'Number',
|
|
|
|
description: 'The document id',
|
|
|
|
http: {source: 'path'}
|
|
|
|
},
|
|
|
|
returns: {
|
|
|
|
type: 'Object',
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:id/removeFile`,
|
|
|
|
verb: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.removeFile = async(ctx, id) => {
|
|
|
|
const models = Self.app.models;
|
|
|
|
const targetClaimDms = await models.ClaimDms.findById(id);
|
|
|
|
const targetDms = await models.Dms.findById(targetClaimDms.dmsFk);
|
|
|
|
const trashDmsType = await models.DmsType.findOne({where: {code: 'trash'}});
|
|
|
|
|
|
|
|
await models.Dms.removeFile(ctx, targetClaimDms.dmsFk);
|
|
|
|
await targetClaimDms.destroy();
|
|
|
|
|
|
|
|
return targetDms.updateAttribute('dmsTypeFk', trashDmsType.id);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|