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

48 lines
1.2 KiB
JavaScript

module.exports = Self => {
Self.remoteMethodCtx('removeFile', {
description: 'Removes a worker document',
accessType: 'WRITE',
accepts: {
arg: 'id',
type: 'Number',
description: 'The worker document id',
http: {source: 'path'}
},
returns: {
type: 'Object',
root: true
},
http: {
path: `/:id/removeFile`,
verb: 'POST'
}
});
Self.removeFile = async(ctx, id, options) => {
const models = Self.app.models;
let tx;
try {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
// const workerDms = await Self.findById(id);
myOptions.model = 'WorkerDms';
await models.Dms.removeFile(ctx, id, myOptions);
// await workerDms.destroy();
if (tx) await tx.commit();
return workerDms;
} catch (e) {
await tx.rollback();
throw e;
}
};
};