Skip to content

Commit 8eeb9a3

Browse files
authored
Merge pull request #1533 from GitVivekHub/Search-By-id-feature
Customer Request #227746 [BE] Search by id filter feature added
2 parents 12553b9 + a722d83 commit 8eeb9a3

File tree

2 files changed

+46
-33
lines changed

2 files changed

+46
-33
lines changed

src/src/beneficiaries/beneficiaries.service.ts

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -743,32 +743,36 @@ export class BeneficiariesService {
743743
let first_name = body.search.split(' ')[0];
744744
let last_name = body.search.split(' ')[1] || '';
745745

746-
if (last_name?.length > 0) {
747-
filterQueryArray.push(`{ _or: [
748-
{ first_name: { _ilike: "%${first_name}%" } },
749-
{ last_name: { _ilike: "%${last_name}%" } },
746+
if (/^\d+$/.test(body?.search)) {
747+
filterQueryArray.push(`{id: { _eq: "${body?.search}"} }`);
748+
} else {
749+
if (last_name?.length > 0) {
750+
filterQueryArray.push(`{ _or: [
751+
{ first_name: { _ilike: "%${first_name}%" } },
752+
{ last_name: { _ilike: "%${last_name}%" } },
753+
{
754+
program_beneficiaries: {
755+
_or: [
756+
{ enrollment_first_name: { _ilike: "%${first_name}%" } },
757+
{ enrollment_last_name: { _ilike: "%${last_name}%" } }
758+
]
759+
}
760+
}
761+
]} `);
762+
} else {
763+
filterQueryArray.push(`{_or: [
764+
{ first_name: { _ilike: "%${first_name}%" } }
765+
{ last_name: { _ilike: "%${first_name}%" } }
750766
{
751767
program_beneficiaries: {
752768
_or: [
753769
{ enrollment_first_name: { _ilike: "%${first_name}%" } },
754-
{ enrollment_last_name: { _ilike: "%${last_name}%" } }
770+
{ enrollment_last_name: { _ilike: "%${first_name}%" } }
755771
]
756772
}
757773
}
758-
]} `);
759-
} else {
760-
filterQueryArray.push(`{_or: [
761-
{ first_name: { _ilike: "%${first_name}%" } }
762-
{ last_name: { _ilike: "%${first_name}%" } }
763-
{
764-
program_beneficiaries: {
765-
_or: [
766-
{ enrollment_first_name: { _ilike: "%${first_name}%" } },
767-
{ enrollment_last_name: { _ilike: "%${first_name}%" } }
768-
]
769-
}
774+
]} `);
770775
}
771-
]} `);
772776
}
773777
}
774778

@@ -900,6 +904,7 @@ export class BeneficiariesService {
900904
offset: offset,
901905
},
902906
};
907+
903908
const response = await this.hasuraServiceFromServices.getData(data);
904909
let mappedResponse = response?.data?.users;
905910
const count = response?.data?.users_aggregate?.aggregate?.count;
@@ -1002,16 +1007,20 @@ export class BeneficiariesService {
10021007
let first_name = body.search.split(' ')[0];
10031008
let last_name = body.search.split(' ')[1] || '';
10041009

1005-
if (last_name?.length > 0) {
1006-
filterQueryArray.push(`{_or: [
1007-
{ first_name: { _ilike: "%${first_name}%" } }
1008-
{ last_name: { _ilike: "%${last_name}%" } }
1009-
]} `);
1010+
if (/^\d+$/.test(body?.search)) {
1011+
filterQueryArray.push(`{id: { _eq: "${body?.search}"} }`);
10101012
} else {
1011-
filterQueryArray.push(`{_or: [
1012-
{ first_name: { _ilike: "%${first_name}%" } }
1013-
{ last_name: { _ilike: "%${first_name}%" } }
1014-
]} `);
1013+
if (last_name?.length > 0) {
1014+
filterQueryArray.push(`{_or: [
1015+
{ first_name: { _ilike: "%${first_name}%" } }
1016+
{ last_name: { _ilike: "%${last_name}%" } }
1017+
]} `);
1018+
} else {
1019+
filterQueryArray.push(`{_or: [
1020+
{ first_name: { _ilike: "%${first_name}%" } }
1021+
{ last_name: { _ilike: "%${first_name}%" } }
1022+
]} `);
1023+
}
10151024
}
10161025
}
10171026
if (body?.is_deactivated && body?.is_deactivated !== '') {

src/src/facilitator/facilitator.service.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,12 +1571,16 @@ export class FacilitatorService {
15711571
);
15721572
variables.qualificationIds = body.qualificationIds;
15731573
}
1574-
if (body.search && body.search !== '') {
1575-
filterQueryArray.push(`{_or: [
1576-
{ first_name: { _ilike: "%${body.search}%" } },
1577-
{ last_name: { _ilike: "%${body.search}%" } },
1578-
{ email_id: { _ilike: "%${body.search}%" } }
1579-
]} `);
1574+
if (body?.search && body?.search !== '') {
1575+
if (/^\d+$/.test(body?.search)) {
1576+
filterQueryArray.push(`{id: { _eq: "${body?.search}"} }`);
1577+
} else {
1578+
filterQueryArray.push(`{_or: [
1579+
{ first_name: { _ilike: "%${body.search}%" } },
1580+
{ last_name: { _ilike: "%${body.search}%" } },
1581+
{ email_id: { _ilike: "%${body.search}%" } }
1582+
]} `);
1583+
}
15801584
}
15811585
if (body.hasOwnProperty('status')) {
15821586
if (

0 commit comments

Comments
 (0)