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

This commit is contained in:
Carlos Satorres 2024-12-19 13:03:21 +01:00
parent 13d7df052a
commit e7c3fa1079
1 changed files with 3 additions and 17 deletions

View File

@ -36,13 +36,7 @@ module.exports = Self => {
arg: 'to',
type: 'date',
description: 'The to date filter',
},
{
arg: 'userId',
type: 'integer',
description: 'The user id',
required: true,
},
}
],
returns: {
type: ['object'],
@ -55,8 +49,6 @@ 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 = {};
@ -80,14 +72,7 @@ module.exports = Self => {
}
});
filter = mergeFilters(ctx.args?.filter ?? {}, {where});
const getRouteByAgency = await models.ACL.checkAccessAcl(ctx, 'Route', 'getRouteByAgency', 'WRITE');
const supplier = await models.Supplier.isSupplier(userId, myOptions);
if (supplier && getRouteByAgency) {
if (!filter.where) filter.where = {};
filter.where[`a.supplierFk`] = supplier.id;
}
filter = mergeFilters(filter, {where});
const date = Date.vnNew();
date.setHours(0, 0, 0, 0);
@ -130,6 +115,7 @@ 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);