fix: refs #7917 fix methods, tests, acls #3085

Closed
carlossa wants to merge 35 commits from 7917-freelancerRoute into dev
5 changed files with 17 additions and 29 deletions
Showing only changes of commit 8f006c5f31 - Show all commits

View File

@ -4058,3 +4058,7 @@ INSERT INTO vn.route (workerFk,firstEditorFk,created,vehicleFk,agencyModeFk,`tim
VALUES (132,100,'2001-01-01 00:00:00.000',1,1,'1899-12-30 12:15:00.000',0,'2001-01-01 00:00:00.000','2001-01-02 00:00:00.000',10.0,1.8,'eighth route',1,0,1,100,'2001-01-01');
INSERT INTO vn.route (workerFk,firstEditorFk,created,vehicleFk,agencyModeFk,`time`,isOk,started,finished,cost,m3,description,zoneFk,priority,invoiceInFk,editorFk,dated)
VALUES (132,100,'2001-01-01 00:00:00.000',1,2,'1899-12-30 13:20:00.000',0,'2001-01-01 00:00:00.000','2001-01-02 00:00:00.000',20.0,0.2,'ninth route',9,0,2,100,'2001-01-01');
UPDATE vn.route
SET workerFk=132
WHERE id=1;

View File

@ -11,6 +11,7 @@ INSERT INTO salix.ACL (model, property, accessType, permission, principalType, p
('Route', 'summary', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer'),
('Route', 'getRouteByAgency', 'WRITE', 'ALLOW', 'ROLE', 'deliveryFreelancer'),
('Route','filter','READ','ALLOW','ROLE','deliveryFreelancer'),
('UserConfig','getUserConfig','*','ALLOW','ROLE','deliveryFreelancer');
('UserConfig','getUserConfig','*','ALLOW','ROLE','deliveryFreelancer'),
('Route', 'getTickets', 'READ', 'ALLOW', 'ROLE', 'deliveryFreelancer');

View File

@ -36,7 +36,13 @@ 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'],
@ -49,6 +55,7 @@ module.exports = Self => {
});
Self.filter = async(ctx, filter, options) => {
const models = Self.app.models;
const conn = Self.dataSource.connector;
const myOptions = {};
@ -72,8 +79,7 @@ module.exports = Self => {
}
});
filter = mergeFilters(filter, {where});
filter = mergeFilters(ctx.args?.filter ?? {}, {where});
const date = Date.vnNew();
date.setHours(0, 0, 0, 0);
const stmts = [];
@ -115,7 +121,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

@ -112,21 +112,11 @@ module.exports = Self => {
filter = mergeFilters(filter, {where});
const worker = await models.Worker.findById(userId, {fields: ['isFreelance']});
console.log('worker: ', worker);
// const user = await models.VnUser.findById(userId, {fields: ['roleFk']});
// console.log('user', user);
// console.log('user.roleFk', user.roleFk);
console.log('filter', filter);
console.log('filter.where', filter.where);
console.log('usedId', userId);
const getMyRoute = await models.ACL.checkAccessAcl(ctx, 'Route', 'getRouteByAgency', 'WRITE');
console.log('getMyRoute: ', getMyRoute);
console.log('worker.isFreelance', worker.isFreelance !== 0);
if (userId && getMyRoute && worker.isFreelance !== 0) {
if (userId && getMyRoute && worker.isFreelance) {
if (!filter.where) filter.where = {};
filter.where[`workerFk`] = userId;
}
console.log('filter', filter);
let stmts = [];
let stmt;

View File

@ -11,12 +11,6 @@ module.exports = Self => {
type: 'object',
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
http: {source: 'query'}
},
{
arg: 'userId',
type: 'integer',
description: 'The user id',
required: true,
}
],
returns: {
@ -29,7 +23,7 @@ module.exports = Self => {
}
});
Self.getTickets = async(ctx, filter, options) => {
Self.getTickets = async(filter, options) => {
const conn = Self.dataSource.connector;
const myOptions = {};
@ -93,18 +87,12 @@ module.exports = Self => {
if (!filter.where) filter.where = {};
const supplier = await Self.app.models.Supplier.isSupplier(ctx.req.accessToken.userId, myOptions);
if (supplier)
filter.where['sat.supplierFk'] = supplier.id;
const where = filter.where;
where['r.id'] = filter.id;
console.log('filter', filter);
stmt.merge(conn.makeWhere(filter.where));
stmt.merge(conn.makeGroupBy('t.id'));
stmt.merge(conn.makeOrderBy(filter.order));
console.log('stmt: ', stmt);
return conn.executeStmt(stmt, myOptions);
};