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

48 lines
1.3 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, options) => {
const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
let tx;
const myOptions = {userId};
if (typeof options == 'object')
Object.assign(myOptions, options);
if (!myOptions.transaction) {
tx = await Self.beginTransaction({});
myOptions.transaction = tx;
}
try {
await Self.rawSql(`CALL vn.routeUpdateM3(?)`, [id], myOptions);
const updatedRoute = await models.Route.findById(id, null, myOptions);
if (tx) await tx.commit();
return updatedRoute;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
};
};