refs #6641 add button my team #2254

Merged
jcasado merged 7 commits from 6641-checkboxMyTeam into dev 2024-04-15 08:11:37 +00:00
4 changed files with 84 additions and 11 deletions

View File

@ -1827,9 +1827,9 @@ INSERT INTO `vn`.`claimState`(`id`, `code`, `description`, `roleFk`, `priority`,
INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `ticketFk`) INSERT INTO `vn`.`claim`(`id`, `ticketCreated`, `claimStateFk`, `clientFk`, `workerFk`, `responsibility`, `isChargedToMana`, `created`, `packages`, `ticketFk`)
VALUES VALUES
(1, util.VN_CURDATE(), 1, 1101, 18, 3, 0, util.VN_CURDATE(), 0, 11), (1, util.VN_CURDATE(), 1, 1101, 19, 3, 0, util.VN_CURDATE(), 0, 11),
(2, util.VN_CURDATE(), 4, 1101, 18, 3, 0, util.VN_CURDATE(), 1, 16), (2, util.VN_CURDATE(), 4, 1101, 18, 3, 0, util.VN_CURDATE(), 1, 16),
(3, util.VN_CURDATE(), 3, 1101, 18, 1, 1, util.VN_CURDATE(), 5, 7), (3, util.VN_CURDATE(), 3, 1101, 19, 1, 1, util.VN_CURDATE(), 5, 7),
(4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, 8); (4, util.VN_CURDATE(), 3, 1104, 18, 5, 0, util.VN_CURDATE(), 10, 8);
INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`) INSERT INTO `vn`.`claimObservation` (`claimFk`, `workerFk`, `text`, `created`)
@ -3761,3 +3761,8 @@ INSERT INTO `vn`.`accountReconciliation` (supplierAccountFk,operationDated,value
INSERT INTO `vn`.`accountReconciliationConfig`(currencyFk, warehouseFk) INSERT INTO `vn`.`accountReconciliationConfig`(currencyFk, warehouseFk)
VALUES (1, 1); VALUES (1, 1);
INSERT INTO vn.workerTeam(id, team, workerFk)
VALUES
(8, 1, 19);

View File

@ -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,7 +127,23 @@ module.exports = Self => {
claimIdsByClaimResponsibleFk = claims.map(claim => claim.claimFk); claimIdsByClaimResponsibleFk = claims.map(claim => claim.claimFk);
} }
const where = buildFilter(args, (param, value) => { // 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(ctx.args, (param, value) => {
switch (param) { switch (param) {
case 'search': case 'search':
return /^\d+$/.test(value) return /^\d+$/.test(value)
@ -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}};
} }
}); });

View File

@ -1,13 +1,25 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
const models = require('vn-loopback/server/server').models;
describe('claim filter()', () => { describe('claim filter()', () => {
let ctx;
beforeEach(() => {
ctx = {
req: {
accessToken: {userId: 9},
headers: {origin: 'http://localhost'}
}
};
});
it('should return 1 result filtering by id', async() => { it('should return 1 result filtering by id', async() => {
const tx = await app.models.Claim.beginTransaction({}); const tx = await app.models.Claim.beginTransaction({});
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const result = await app.models.Claim.filter({args: {filter: {}, search: 1}}, null, options); ctx.args = {search: 1};
jcasado marked this conversation as resolved Outdated
Outdated
Review

Veo mas como y legible poner en la linea de antes ctx.args = {search: 1}
Y luego usar directamente .. models.Claim.filter(ctx, null, options);

Igual en los otros casos

Veo mas como y legible poner en la linea de antes `ctx.args = {search: 1}` Y luego usar directamente `.. models.Claim.filter(ctx, null, options);` Igual en los otros casos
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(1); expect(result.length).toEqual(1);
expect(result[0].id).toEqual(1); expect(result[0].id).toEqual(1);
@ -25,7 +37,8 @@ describe('claim filter()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const result = await app.models.Claim.filter({args: {filter: {}, search: 'Tony Stark'}}, null, options); ctx.args = {search: 'Tony Stark'};
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(1); expect(result.length).toEqual(1);
expect(result[0].id).toEqual(4); expect(result[0].id).toEqual(4);
@ -43,7 +56,8 @@ describe('claim filter()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const result = await app.models.Claim.filter({args: {filter: {}, workerFk: 18}}, null, options); ctx.args = {workerFk: 18};
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(4); expect(result.length).toEqual(4);
expect(result[0].id).toEqual(1); expect(result[0].id).toEqual(1);
@ -64,7 +78,8 @@ describe('claim filter()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const result = await app.models.Claim.filter({args: {filter: {}, itemFk: 2}}, null, options); ctx.args = {itemFk: 2};
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(3); expect(result.length).toEqual(3);
expect(result[0].id).toEqual(1); expect(result[0].id).toEqual(1);
@ -84,7 +99,8 @@ describe('claim filter()', () => {
try { try {
const options = {transaction: tx}; const options = {transaction: tx};
const result = await app.models.Claim.filter({args: {filter: {}, claimResponsibleFk: 7}}, null, options); ctx.args = {claimResponsibleFk: 7};
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(3); expect(result.length).toEqual(3);
expect(result[0].id).toEqual(2); expect(result[0].id).toEqual(2);
@ -97,4 +113,22 @@ describe('claim filter()', () => {
throw e; throw e;
} }
}); });
it('should now return claims from the worker team', async() => {
const tx = await models.Claim.beginTransaction({});
try {
const options = {transaction: tx};
ctx.args = {itemFk: null, myTeam: true};
const result = await app.models.Claim.filter(ctx, null, options);
expect(result.length).toEqual(2);
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
}); });

View File

@ -70,6 +70,13 @@
label="Responsible"> label="Responsible">
</vn-autocomplete> </vn-autocomplete>
</vn-horizontal> </vn-horizontal>
<vn-horizontal>
<vn-check
vn-one
label="My team"
ng-model="filter.myTeam"
triple-state="true">
</vn-horizontal>
<vn-horizontal class="vn-mt-lg"> <vn-horizontal class="vn-mt-lg">
<vn-submit label="Search"></vn-submit> <vn-submit label="Search"></vn-submit>
</vn-horizontal> </vn-horizontal>