salix/modules/route/back/methods/route/updateVolume.js

43 lines
1.2 KiB
JavaScript

module.exports = Self => {
Self.remoteMethodCtx('updateVolume', {
description: 'Update the volume in a route',
accessType: 'WRITE',
accepts: {
arg: 'id',
type: 'number',
required: true,
description: 'Route id',
http: {source: 'path'}
},
returns: {
type: 'number',
root: true
},
http: {
path: `/:id/updateVolume`,
verb: 'POST'
}
});
Self.updateVolume = async(ctx, id) => {
let query = `CALL vn.routeUpdateM3(?)`;
let userId = ctx.req.accessToken.userId;
let originalRoute = await Self.app.models.Route.findById(id);
await Self.rawSql(query, [id]);
let updatedRoute = await Self.app.models.Route.findById(id);
let logRecord = {
originFk: id,
userFk: userId,
action: 'update',
changedModel: 'Route',
changedModelId: id,
oldInstance: {m3: originalRoute.m3},
newInstance: {m3: updatedRoute.m3}
};
return await Self.app.models.RouteLog.create(logRecord);
};
};