diff --git a/modules/claim/back/methods/claim/filter.js b/modules/claim/back/methods/claim/filter.js
index 2daee6413..b1d1cb3a7 100644
--- a/modules/claim/back/methods/claim/filter.js
+++ b/modules/claim/back/methods/claim/filter.js
@@ -79,7 +79,12 @@ module.exports = Self => {
type: 'number',
description: 'The claimResponsible id',
http: {source: 'query'}
- }
+ },
+ {
+ arg: 'myTeam',
+ type: 'boolean',
+ description: `Team partners`
+ },
],
returns: {
type: ['object'],
@@ -92,6 +97,7 @@ module.exports = Self => {
});
Self.filter = async(ctx, filter, options) => {
+ const userId = ctx.req.accessToken.userId;
const models = Self.app.models;
const conn = Self.dataSource.connector;
const args = ctx.args;
@@ -121,6 +127,22 @@ module.exports = Self => {
claimIdsByClaimResponsibleFk = claims.map(claim => claim.claimFk);
}
+ // 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)
+ teamMembersId.push(userId);
+ }
+
const where = buildFilter(args, (param, value) => {
switch (param) {
case 'search':
@@ -152,6 +174,11 @@ module.exports = Self => {
to.setHours(23, 59, 59, 999);
return {'cl.created': {between: [value, to]}};
+ case 'myTeam':
+ if (value)
+ return {'cl.workerFk': {inq: teamMembersId}};
+ else
+ return {'cl.workerFk': {nin: teamMembersId}};
}
});
diff --git a/modules/claim/back/methods/claim/specs/filter.spec.js b/modules/claim/back/methods/claim/specs/filter.spec.js
index 49e258505..a25ec8d27 100644
--- a/modules/claim/back/methods/claim/specs/filter.spec.js
+++ b/modules/claim/back/methods/claim/specs/filter.spec.js
@@ -97,4 +97,23 @@ describe('claim filter()', () => {
throw e;
}
});
+
+ it('should now return the tickets from the worker team', async() => {
+ const tx = await models.Claim.beginTransaction({});
+
+ try {
+ const options = {transaction: tx};
+
+ const ctx = {req: {accessToken: {userId: 18}}, args: {myTeam: true}};
+ const filter = {};
+ const result = await models.SalesMonitor.salesFilter(ctx, filter, options);
+
+ expect(result.length).toBeGreaterThan(20);
+
+ await tx.rollback();
+ } catch (e) {
+ await tx.rollback();
+ throw e;
+ }
+ });
});
diff --git a/modules/claim/front/search-panel/index.html b/modules/claim/front/search-panel/index.html
index 6465eb621..260f86801 100644
--- a/modules/claim/front/search-panel/index.html
+++ b/modules/claim/front/search-panel/index.html
@@ -70,15 +70,15 @@
label="Responsible">
-
-
-
-
+
+
+
+