refs #6014 feat: executeRoutine
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Alex Moreno 2023-10-18 15:22:04 +02:00
parent 71937699a4
commit 4d3d38ebe3
1 changed files with 61 additions and 0 deletions

View File

@ -0,0 +1,61 @@
module.exports = Self => {
Self.remoteMethodCtx('executeRoutine', {
description: 'Return the routes by worker',
accessType: '*',
accepts: [
{
arg: 'routine',
type: 'string',
description: 'The routine sql',
required: true,
http: {source: 'path'}
},
{
arg: 'params',
type: ['any'],
description: 'The array of params',
required: true,
}
],
returns: {
type: 'any',
root: true
},
http: {
path: `/:routine/execute-routine`,
verb: 'POST'
}
});
Self.executeRoutine = async(ctx, routine, params, options) => {
const userId = ctx.req.accessToken.userId;
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const user = await Self.app.models.VnUser.findById(userId, {
fields: ['id', 'roleFk'],
include: {
relation: 'role',
scope: {
fields: ['id', 'name']
}
}
});
const inherits = await Self.app.models.RoleRole.find({
where: {
}
});
console.log(user.role.name);
const checkACL = await models.ACL.checkAccessAcl(ctx, 'Application', routine, '*');
if (!checkACL) throw error;
const requestParams = [routine];
requestParams.concat(params);
return Self.app.models.Route.rawSql(`CALL ?(...)`, requestParams, myOptions);
};
};