module.exports = Self => { Self.remoteMethodCtx('removeFile', { description: 'Removes a ticket document', 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); }; };