2019-06-06 11:59:11 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethodCtx('removeFile', {
|
|
|
|
description: 'Removes a ticket document',
|
|
|
|
accessType: 'WRITE',
|
|
|
|
accepts: {
|
|
|
|
arg: 'id',
|
2021-10-07 07:57:07 +00:00
|
|
|
type: 'number',
|
2019-06-06 11:59:11 +00:00
|
|
|
description: 'The document id',
|
|
|
|
http: {source: 'path'}
|
|
|
|
},
|
|
|
|
returns: {
|
2021-10-07 07:57:07 +00:00
|
|
|
type: 'object',
|
2019-06-06 11:59:11 +00:00
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:id/removeFile`,
|
|
|
|
verb: 'POST'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
Self.removeFile = async(ctx, id, options) => {
|
|
|
|
const myOptions = {};
|
|
|
|
let tx;
|
2019-06-06 11:59:11 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
if (typeof options == 'object')
|
|
|
|
Object.assign(myOptions, options);
|
2019-06-06 11:59:11 +00:00
|
|
|
|
2021-10-07 07:57:07 +00:00
|
|
|
if (!myOptions.transaction) {
|
|
|
|
tx = await Self.beginTransaction({});
|
|
|
|
myOptions.transaction = tx;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
2023-12-12 11:09:06 +00:00
|
|
|
// const targetTicketDms = await models.TicketDms.findById(id, null, myOptions);
|
|
|
|
myOptions.model = 'TicketDms';
|
|
|
|
// await models.Dms.findById(targetTicketDms.dmsFk, null, myOptions);
|
|
|
|
// const trashDmsType = await models.DmsType.findOne({where: {code: 'trash'}}, myOptions);
|
2021-10-07 07:57:07 +00:00
|
|
|
|
2023-12-12 11:09:06 +00:00
|
|
|
const targetDms = await Self.app.models.Dms.removeFile(ctx, id, myOptions);
|
|
|
|
// await targetTicketDms.destroy(myOptions);
|
2021-10-07 07:57:07 +00:00
|
|
|
|
2023-12-12 11:09:06 +00:00
|
|
|
// await targetDms.updateAttribute('dmsTypeFk', trashDmsType.id, myOptions);
|
2021-10-07 07:57:07 +00:00
|
|
|
|
|
|
|
if (tx) await tx.commit();
|
|
|
|
|
|
|
|
return targetDms;
|
|
|
|
} catch (e) {
|
|
|
|
if (tx) await tx.rollback();
|
|
|
|
throw e;
|
|
|
|
}
|
2019-06-06 11:59:11 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|