From 6f66b6b5ff222c902589ad666177eaffa51ffa3f Mon Sep 17 00:00:00 2001 From: carlossa Date: Mon, 2 Dec 2024 13:01:18 +0100 Subject: [PATCH] fix: refs #7917 freelancer route --- modules/route/back/methods/agency-term/filter.js | 5 +++-- modules/supplier/back/models/supplier.js | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/route/back/methods/agency-term/filter.js b/modules/route/back/methods/agency-term/filter.js index f60966649..9ab56da79 100644 --- a/modules/route/back/methods/agency-term/filter.js +++ b/modules/route/back/methods/agency-term/filter.js @@ -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); diff --git a/modules/supplier/back/models/supplier.js b/modules/supplier/back/models/supplier.js index acf68275f..7daa42387 100644 --- a/modules/supplier/back/models/supplier.js +++ b/modules/supplier/back/models/supplier.js @@ -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;