8524-devToTest #3415

Merged
alexm merged 343 commits from 8524-devToTest into test 2025-02-04 13:42:16 +00:00
8 changed files with 86 additions and 88 deletions
Showing only changes of commit 0eff155daf - Show all commits

View File

@ -109,6 +109,7 @@ module.exports = Self => {
const args = ctx.args; const args = ctx.args;
const myOptions = {}; const myOptions = {};
let to; let to;
const myTeamIds = [];
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
@ -133,21 +134,8 @@ module.exports = Self => {
claimIdsByClaimResponsibleFk = claims.map(claim => claim.claimFk); claimIdsByClaimResponsibleFk = claims.map(claim => claim.claimFk);
} }
// Apply filter by team if (args.myTeam != null)
const teamMembersId = []; myTeamIds.value = await models.Worker.myTeam(userId);
if (args.myTeam != null) {
const worker = await models.Worker.findById(userId, {
include: {
relation: 'collegues'
}
}, myOptions);
const collegues = worker.collegues() || [];
for (let collegue of collegues)
teamMembersId.push(collegue.collegueFk);
if (teamMembersId.length == 0)
teamMembersId.push(userId);
}
const where = buildFilter(ctx.args, (param, value) => { const where = buildFilter(ctx.args, (param, value) => {
switch (param) { switch (param) {
@ -184,9 +172,9 @@ module.exports = Self => {
return {'t.zoneFk': value}; return {'t.zoneFk': value};
case 'myTeam': case 'myTeam':
if (value) if (value)
return {'cl.workerFk': {inq: teamMembersId}}; return {'cl.workerFk': {inq: myTeamIds.value}};
else else
return {'cl.workerFk': {nin: teamMembersId}}; return {'cl.workerFk': {nin: myTeamIds.value}};
} }
}); });

View File

@ -123,25 +123,13 @@ module.exports = Self => {
date.setHours(0, 0, 0, 0); date.setHours(0, 0, 0, 0);
const args = ctx.args; const args = ctx.args;
const myOptions = {}; const myOptions = {};
const myTeamIds = [];
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
// Apply filter by team if (args.myTeam != null)
const teamMembersId = []; myTeamIds.value = await models.Worker.myTeam(userId);
if (args.myTeam != null) {
const worker = await models.Worker.findById(userId, {
include: {
relation: 'collegues'
}
}, myOptions);
const collegues = worker.collegues() || [];
for (let collegue of collegues)
teamMembersId.push(collegue.collegueFk);
if (teamMembersId.length == 0)
teamMembersId.push(userId);
}
if (ctx.args && args.to) { if (ctx.args && args.to) {
const dateTo = args.to; const dateTo = args.to;
@ -163,9 +151,9 @@ module.exports = Self => {
case 'mine': case 'mine':
case 'myTeam': case 'myTeam':
if (value) if (value)
return {'c.salesPersonFk': {inq: teamMembersId}}; return {'c.salesPersonFk': {inq: myTeamIds.value}};
else else
return {'c.salesPersonFk': {nin: teamMembersId}}; return {'c.salesPersonFk': {nin: myTeamIds.value}};
case 'id': case 'id':
case 'clientFk': case 'clientFk':
param = `t.${param}`; param = `t.${param}`;

View File

@ -80,29 +80,15 @@ module.exports = Self => {
const conn = Self.dataSource.connector; const conn = Self.dataSource.connector;
const myOptions = {}; const myOptions = {};
const userId = ctx.req.accessToken.userId; const userId = ctx.req.accessToken.userId;
const myTeamIds = [];
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const args = ctx.args; const args = ctx.args;
// Apply filter by team
const teamMembersId = [];
if (args.myTeam != null) {
const worker = await models.Worker.findById(userId, {
include: {
relation: 'collegues'
}
}, myOptions);
const collegues = worker.collegues() || [];
for (let collegue of collegues)
teamMembersId.push(collegue.collegueFk);
if (teamMembersId.length == 0) if (args.myTeam != null)
teamMembersId.push(userId); myTeamIds.value = await models.Worker.myTeam(userId);
}
if (args?.myTeam)
args.teamIds = teamIds;
if (args?.to) if (args?.to)
args.to.setHours(23, 59, 0, 0); args.to.setHours(23, 59, 0, 0);
@ -133,9 +119,9 @@ module.exports = Self => {
return {'o.confirmed': value ? 1 : 0}; return {'o.confirmed': value ? 1 : 0};
case 'myTeam': case 'myTeam':
if (value) if (value)
return {'c.salesPersonFk': {inq: teamMembersId}}; return {'c.salesPersonFk': {inq: myTeamIds.value}};
else else
return {'c.salesPersonFk': {nin: teamMembersId}}; return {'c.salesPersonFk': {nin: myTeamIds.value}};
case 'showEmpty': case 'showEmpty':
return {'o.total': {neq: value}}; return {'o.total': {neq: value}};
case 'id': case 'id':

View File

@ -87,6 +87,7 @@ module.exports = Self => {
const myOptions = {}; const myOptions = {};
const models = Self.app.models; const models = Self.app.models;
const args = ctx.args; const args = ctx.args;
const myTeamIds = [];
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
@ -94,20 +95,8 @@ module.exports = Self => {
if (ctx.args.mine) if (ctx.args.mine)
ctx.args.attenderFk = userId; ctx.args.attenderFk = userId;
const teamMembersId = []; if (args.myTeam != null)
if (args.myTeam != null) { myTeamIds.value = await models.Worker.myTeam(userId);
const worker = await models.Worker.findById(userId, {
include: {
relation: 'collegues'
}
}, myOptions);
const collegues = worker.collegues() || [];
for (let collegue of collegues)
teamMembersId.push(collegue.collegueFk);
if (teamMembersId.length == 0)
teamMembersId.push(userId);
}
const today = Date.vnNew(); const today = Date.vnNew();
const future = Date.vnNew(); const future = Date.vnNew();
@ -145,9 +134,9 @@ module.exports = Self => {
return {'c.salesPersonFk': value}; return {'c.salesPersonFk': value};
case 'myTeam': case 'myTeam':
if (value) if (value)
return {'tr.requesterFk': {inq: teamMembersId}}; return {'tr.requesterFk': {inq: myTeamIds.value}};
else else
return {'tr.requesterFk': {nin: teamMembersId}}; return {'tr.requesterFk': {nin: myTeamIds.value}};
case 'daysOnward': case 'daysOnward':
today.setHours(0, 0, 0, 0); today.setHours(0, 0, 0, 0);
future.setDate(today.getDate() + value); future.setDate(today.getDate() + value);

View File

@ -142,28 +142,14 @@ module.exports = Self => {
date.setHours(0, 0, 0, 0); date.setHours(0, 0, 0, 0);
const models = Self.app.models; const models = Self.app.models;
const args = ctx.args; const args = ctx.args;
const myTeamIds = [];
const myOptions = {}; const myOptions = {};
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
// Apply filter by team if (args.myTeam != null)
const teamMembersId = []; myTeamIds.value = await models.Worker.myTeam(userId);
if (args.myTeam != null) {
const worker = await models.Worker.findById(userId, {
include: {
relation: 'collegues'
}
}, myOptions);
const collegues = worker.collegues() || [];
for (let collegue of collegues)
teamMembersId.push(collegue.collegueFk);
if (teamMembersId.length == 0)
teamMembersId.push(userId);
}
if (ctx.args && args.to) { if (ctx.args && args.to) {
const dateTo = args.to; const dateTo = args.to;
@ -195,9 +181,9 @@ module.exports = Self => {
case 'mine': case 'mine':
case 'myTeam': case 'myTeam':
if (value) if (value)
return {'c.salesPersonFk': {inq: teamMembersId}}; return {'c.salesPersonFk': {inq: myTeamIds.value}};
else else
return {'c.salesPersonFk': {nin: teamMembersId}}; return {'c.salesPersonFk': {nin: myTeamIds.value}};
case 'alertLevel': case 'alertLevel':
return {'ts.alertLevel': value}; return {'ts.alertLevel': value};

View File

@ -73,6 +73,11 @@ module.exports = Self => {
type: 'String', type: 'String',
description: 'The user email', description: 'The user email',
http: {source: 'query'} http: {source: 'query'}
},
{
arg: 'myTeam',
type: 'boolean',
description: 'Whether to show only tickets for the current logged user team (currently user tickets)'
} }
], ],
returns: { returns: {
@ -87,6 +92,13 @@ module.exports = Self => {
Self.filter = async(ctx, filter) => { Self.filter = async(ctx, filter) => {
let conn = Self.dataSource.connector; let conn = Self.dataSource.connector;
const models = Self.app.models;
const userId = ctx.req.accessToken.userId;
const args = ctx.args;
const myTeamIds = [];
if (args.myTeam != null)
myTeamIds.value = await models.Worker.myTeam(userId);
let where = buildFilter(ctx.args, (param, value) => { let where = buildFilter(ctx.args, (param, value) => {
switch (param) { switch (param) {
@ -117,6 +129,11 @@ module.exports = Self => {
return {'u.name': {like: `%${value}%`}}; return {'u.name': {like: `%${value}%`}};
case 'email': case 'email':
return {'eu.email': {like: `%${value}%`}}; return {'eu.email': {like: `%${value}%`}};
case 'myTeam':
if (value)
return {'c.salesPersonFk': {inq: myTeamIds.value}};
else
return {'c.salesPersonFk': {nin: myTeamIds.value}};
} }
}); });

View File

@ -0,0 +1,43 @@
module.exports = Self => {
Self.remoteMethod('myTeam', {
description: 'Return the members of the user team',
accessType: 'READ',
accepts: [{
arg: 'userId',
type: 'string',
required: true
}],
returns: {
type: 'string',
root: true
},
http: {
path: `/myTeam`,
verb: 'GET'
}
});
Self.myTeam = async(userId, options) => {
const models = Self.app.models;
const myOptions = {};
const teamMembersId = [];
if (typeof options == 'object')
Object.assign(myOptions, options);
const worker = await models.Worker.findById(userId, {
include: {
relation: 'collegues'
}
}, myOptions);
const collegues = worker.collegues() || [];
for (let collegue of collegues)
teamMembersId.push(collegue.collegueFk);
if (teamMembersId.length == 0)
teamMembersId.push(userId);
return teamMembersId;
};
};

View File

@ -21,6 +21,7 @@ module.exports = Self => {
require('../methods/worker/isAuthorized')(Self); require('../methods/worker/isAuthorized')(Self);
require('../methods/worker/setPassword')(Self); require('../methods/worker/setPassword')(Self);
require('../methods/worker/getAvailablePda')(Self); require('../methods/worker/getAvailablePda')(Self);
require('../methods/worker/myTeam')(Self);
Self.validateAsync('fi', tinIsValid, { Self.validateAsync('fi', tinIsValid, {
message: 'Invalid TIN' message: 'Invalid TIN'