7253-devToTest_2418 #2350
|
@ -79,7 +79,12 @@ module.exports = Self => {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
description: 'The claimResponsible id',
|
description: 'The claimResponsible id',
|
||||||
http: {source: 'query'}
|
http: {source: 'query'}
|
||||||
}
|
},
|
||||||
|
{
|
||||||
|
arg: 'myTeam',
|
||||||
|
type: 'boolean',
|
||||||
|
description: `Team partners`
|
||||||
|
},
|
||||||
],
|
],
|
||||||
returns: {
|
returns: {
|
||||||
type: ['object'],
|
type: ['object'],
|
||||||
|
@ -92,6 +97,7 @@ module.exports = Self => {
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.filter = async(ctx, filter, options) => {
|
Self.filter = async(ctx, filter, options) => {
|
||||||
|
const userId = ctx.req.accessToken.userId;
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
|
@ -121,6 +127,22 @@ module.exports = Self => {
|
||||||
claimIdsByClaimResponsibleFk = claims.map(claim => claim.claimFk);
|
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) => {
|
const where = buildFilter(args, (param, value) => {
|
||||||
switch (param) {
|
switch (param) {
|
||||||
case 'search':
|
case 'search':
|
||||||
|
@ -152,6 +174,11 @@ module.exports = Self => {
|
||||||
to.setHours(23, 59, 59, 999);
|
to.setHours(23, 59, 59, 999);
|
||||||
|
|
||||||
return {'cl.created': {between: [value, to]}};
|
return {'cl.created': {between: [value, to]}};
|
||||||
|
case 'myTeam':
|
||||||
|
if (value)
|
||||||
|
return {'cl.workerFk': {inq: teamMembersId}};
|
||||||
|
else
|
||||||
|
return {'cl.workerFk': {nin: teamMembersId}};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -97,4 +97,23 @@ describe('claim filter()', () => {
|
||||||
throw e;
|
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;
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -70,15 +70,15 @@
|
||||||
label="Responsible">
|
label="Responsible">
|
||||||
</vn-autocomplete>
|
</vn-autocomplete>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<vn-horizontal class="vn-mt-lg">
|
<vn-horizontal>
|
||||||
<vn-submit label="Search"></vn-submit>
|
|
||||||
</vn-horizontal>
|
|
||||||
<vn-horizontal class="vn-px-lg">
|
|
||||||
<vn-check
|
<vn-check
|
||||||
vn-one
|
vn-one
|
||||||
label="My team"
|
label="My team"
|
||||||
ng-model="filter.myTeam"
|
ng-model="filter.myTeam"
|
||||||
triple-state="true">
|
triple-state="true">
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
|
<vn-horizontal class="vn-mt-lg">
|
||||||
|
<vn-submit label="Search"></vn-submit>
|
||||||
|
</vn-horizontal>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue