Skip to content

Commit

Permalink
Merge pull request #1533 from GitVivekHub/Search-By-id-feature
Browse files Browse the repository at this point in the history
Customer Request #227746 [BE] Search by id filter feature added
  • Loading branch information
rushi-tekdi authored Sep 25, 2024
2 parents 12553b9 + a722d83 commit 8eeb9a3
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 33 deletions.
63 changes: 36 additions & 27 deletions src/src/beneficiaries/beneficiaries.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -743,32 +743,36 @@ export class BeneficiariesService {
let first_name = body.search.split(' ')[0];
let last_name = body.search.split(' ')[1] || '';

if (last_name?.length > 0) {
filterQueryArray.push(`{ _or: [
{ first_name: { _ilike: "%${first_name}%" } },
{ last_name: { _ilike: "%${last_name}%" } },
if (/^\d+$/.test(body?.search)) {
filterQueryArray.push(`{id: { _eq: "${body?.search}"} }`);
} else {
if (last_name?.length > 0) {
filterQueryArray.push(`{ _or: [
{ first_name: { _ilike: "%${first_name}%" } },
{ last_name: { _ilike: "%${last_name}%" } },
{
program_beneficiaries: {
_or: [
{ enrollment_first_name: { _ilike: "%${first_name}%" } },
{ enrollment_last_name: { _ilike: "%${last_name}%" } }
]
}
}
]} `);
} else {
filterQueryArray.push(`{_or: [
{ first_name: { _ilike: "%${first_name}%" } }
{ last_name: { _ilike: "%${first_name}%" } }
{
program_beneficiaries: {
_or: [
{ enrollment_first_name: { _ilike: "%${first_name}%" } },
{ enrollment_last_name: { _ilike: "%${last_name}%" } }
{ enrollment_last_name: { _ilike: "%${first_name}%" } }
]
}
}
]} `);
} else {
filterQueryArray.push(`{_or: [
{ first_name: { _ilike: "%${first_name}%" } }
{ last_name: { _ilike: "%${first_name}%" } }
{
program_beneficiaries: {
_or: [
{ enrollment_first_name: { _ilike: "%${first_name}%" } },
{ enrollment_last_name: { _ilike: "%${first_name}%" } }
]
}
]} `);
}
]} `);
}
}

Expand Down Expand Up @@ -900,6 +904,7 @@ export class BeneficiariesService {
offset: offset,
},
};

const response = await this.hasuraServiceFromServices.getData(data);
let mappedResponse = response?.data?.users;
const count = response?.data?.users_aggregate?.aggregate?.count;
Expand Down Expand Up @@ -1002,16 +1007,20 @@ export class BeneficiariesService {
let first_name = body.search.split(' ')[0];
let last_name = body.search.split(' ')[1] || '';

if (last_name?.length > 0) {
filterQueryArray.push(`{_or: [
{ first_name: { _ilike: "%${first_name}%" } }
{ last_name: { _ilike: "%${last_name}%" } }
]} `);
if (/^\d+$/.test(body?.search)) {
filterQueryArray.push(`{id: { _eq: "${body?.search}"} }`);
} else {
filterQueryArray.push(`{_or: [
{ first_name: { _ilike: "%${first_name}%" } }
{ last_name: { _ilike: "%${first_name}%" } }
]} `);
if (last_name?.length > 0) {
filterQueryArray.push(`{_or: [
{ first_name: { _ilike: "%${first_name}%" } }
{ last_name: { _ilike: "%${last_name}%" } }
]} `);
} else {
filterQueryArray.push(`{_or: [
{ first_name: { _ilike: "%${first_name}%" } }
{ last_name: { _ilike: "%${first_name}%" } }
]} `);
}
}
}
if (body?.is_deactivated && body?.is_deactivated !== '') {
Expand Down
16 changes: 10 additions & 6 deletions src/src/facilitator/facilitator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1571,12 +1571,16 @@ export class FacilitatorService {
);
variables.qualificationIds = body.qualificationIds;
}
if (body.search && body.search !== '') {
filterQueryArray.push(`{_or: [
{ first_name: { _ilike: "%${body.search}%" } },
{ last_name: { _ilike: "%${body.search}%" } },
{ email_id: { _ilike: "%${body.search}%" } }
]} `);
if (body?.search && body?.search !== '') {
if (/^\d+$/.test(body?.search)) {
filterQueryArray.push(`{id: { _eq: "${body?.search}"} }`);
} else {
filterQueryArray.push(`{_or: [
{ first_name: { _ilike: "%${body.search}%" } },
{ last_name: { _ilike: "%${body.search}%" } },
{ email_id: { _ilike: "%${body.search}%" } }
]} `);
}
}
if (body.hasOwnProperty('status')) {
if (
Expand Down

0 comments on commit 8eeb9a3

Please sign in to comment.