fix: refs #7917 freelancer route
gitea/salix/pipeline/pr-dev There was a failure building this commit Details

This commit is contained in:
Carlos Satorres 2024-12-02 13:01:18 +01:00
parent bb9c525f2d
commit 6f66b6b5ff
2 changed files with 4 additions and 4 deletions

View File

@ -49,6 +49,8 @@ module.exports = Self => {
});
Self.filter = async(ctx, filter, options) => {
const models = Self.app.models;
const userId = ctx.req.accessToken.userId;
const conn = Self.dataSource.connector;
const myOptions = {};
@ -75,7 +77,7 @@ module.exports = Self => {
filter = mergeFilters(ctx.args?.filter ?? {}, {where});
const getRouteByAgency = await models.ACL.checkAccessAcl(ctx, 'Route', 'getRouteByAgency', 'WRITE');
const supplier = await Self.app.models.Supplier.isSupplier(ctx, myOptions);
const supplier = await models.Supplier.isSupplier(userId, myOptions);
if (supplier && getRouteByAgency) {
if (!filter.where) filter.where = {};
filter.where[`a.supplierFk`] = supplier.id;
@ -122,7 +124,6 @@ module.exports = Self => {
const sql = ParameterizedSQL.join(stmts, ';');
const result = await conn.executeStmt(sql, myOptions);
const models = Self.app.models;
for (let agencyTerm of result)
agencyTerm.route = await models.Route.findById(agencyTerm.routeFk);

View File

@ -164,13 +164,12 @@ module.exports = Self => {
throw new UserError('The social name has an invalid format');
});
Self.isSupplier = async(ctx, options) => {
Self.isSupplier = async(userId, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const userId = ctx.req.accessToken.userId;
const client = await Self.app.models.Client.findById(userId, null, myOptions);
const supplier = await Self.app.models.Supplier.findOne({where: {nif: client.fi}}, myOptions);
return supplier;