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

51 lines
1.4 KiB
JavaScript
Raw Normal View History

2019-04-04 11:06:41 +00:00
module.exports = Self => {
2020-12-21 11:37:36 +00:00
Self.remoteMethodCtx('guessPriority', {
2019-04-04 11:06:41 +00:00
description: 'Changes automatically the priority of the tickets in a route',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
2019-06-21 11:19:51 +00:00
description: 'Route Id ',
2019-04-04 11:06:41 +00:00
http: {source: 'path'}
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/:id/guessPriority`,
verb: 'GET'
}
});
2020-12-21 11:37:36 +00:00
Self.guessPriority = async(ctx, id) => {
const userId = ctx.req.accessToken.userId;
const $t = ctx.req.__; // $translate
const query = `CALL vn.routeGuessPriority(?)`;
const tx = await Self.beginTransaction({});
2019-04-04 11:06:41 +00:00
2020-12-21 11:37:36 +00:00
try {
let options = {transaction: tx};
const priority = await Self.rawSql(query, [id], options);
let logRecord = {
originFk: id,
userFk: userId,
action: 'update',
changedModel: 'Route',
description: $t('Sorts whole route')
};
await Self.app.models.RouteLog.create(logRecord, options);
await tx.commit();
return priority;
} catch (e) {
await tx.rollback();
throw e;
}
2019-04-04 11:06:41 +00:00
};
};