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

40 lines
1.0 KiB
JavaScript

module.exports = Self => {
Self.remoteMethodCtx('guessPriority', {
description: 'Changes automatically the priority of the tickets in a route',
accessType: 'WRITE',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'Route Id ',
http: {source: 'path'}
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/:id/guessPriority`,
verb: 'PATCH'
}
});
Self.guessPriority = async(ctx, id) => {
const userId = ctx.req.accessToken.userId;
const query = `CALL vn.routeGuessPriority(?)`;
const tx = await Self.beginTransaction({});
try {
let options = {transaction: tx, userId};
const priority = await Self.rawSql(query, [id], options);
await tx.commit();
return priority;
} catch (e) {
await tx.rollback();
throw e;
}
};
};