38 lines
1.0 KiB
JavaScript
38 lines
1.0 KiB
JavaScript
|
|
module.exports = Self => {
|
|
Self.remoteMethodCtx('deleteThermograph', {
|
|
description: 'Deletes a travel thermograph',
|
|
accessType: 'WRITE',
|
|
accepts: {
|
|
arg: 'id',
|
|
type: 'Number',
|
|
description: 'The thermograph id',
|
|
required: true
|
|
},
|
|
returns: {
|
|
type: 'object',
|
|
root: true
|
|
},
|
|
http: {
|
|
path: '/deleteThermograph',
|
|
verb: 'DELETE'
|
|
}
|
|
});
|
|
|
|
Self.deleteThermograph = async(ctx, id) => {
|
|
const models = Self.app.models;
|
|
const userId = ctx.req.accessToken.userId;
|
|
const travelThermograph = await models.TravelThermograph.findById(id);
|
|
|
|
await models.Dms.removeFile(ctx, travelThermograph.dmsFk);
|
|
await Self.rawSql(`
|
|
UPDATE travelThermograph
|
|
SET travelFk = NULL, dmsFk = NULL
|
|
WHERE id = ?`, [id], {userId});
|
|
|
|
travelThermograph.travelFk = null;
|
|
travelThermograph.dmsFk = null;
|
|
return travelThermograph;
|
|
};
|
|
};
|