salix/modules/claim/back/methods/claim-dms/removeFile.js

54 lines
1.6 KiB
JavaScript
Raw Normal View History

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',
2019-07-30 06:51:38 +00:00
description: 'The document id',
http: {source: 'path'}
},
returns: {
type: 'object',
2019-07-30 06:51:38 +00:00
root: true
},
http: {
path: `/:id/removeFile`,
verb: 'POST'
}
});
Self.removeFile = async(ctx, id, options) => {
let tx;
const myOptions = {};
2019-07-30 06:51:38 +00:00
if (typeof options == 'object')
Object.assign(myOptions, options);
2019-07-30 06:51:38 +00:00
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
2023-12-12 11:09:06 +00:00
// const {models: ClaimDms, Dms} = Self.app.models;
// const targetClaimDms = await ClaimDms.findById(id, null, myOptions);
// await Dms.findById(targetClaimDms.dmsFk, null, myOptions);
// const trashDmsType = await DmsType.findOne({where: {code: 'trash'}}, myOptions);
myOptions.model = 'ClaimDms';
const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions);
// await targetClaimDms.destroy(myOptions);
// await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions);
if (tx) await tx.commit();
return targetDms;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
2019-07-30 06:51:38 +00:00
};
};