54 lines
1.5 KiB
JavaScript
54 lines
1.5 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]);
|
|
|
|
const oldInstance = {
|
|
travelFk: travelThermograph.travelFk,
|
|
dmsFk: travelThermograph.dmsFk
|
|
};
|
|
|
|
await models.TravelLog.create({
|
|
originFk: travelThermograph.travelFk,
|
|
userFk: userId,
|
|
action: 'delete',
|
|
changedModel: 'TravelThermograph',
|
|
changedModelId: id,
|
|
oldInstance: oldInstance,
|
|
newInstance: {}
|
|
});
|
|
|
|
travelThermograph.travelFk = null;
|
|
travelThermograph.dmsFk = null;
|
|
|
|
return travelThermograph;
|
|
};
|
|
};
|