Skip to content

Commit f9c0a8a

Browse files
committed
Search by id feature added
1 parent 11489c9 commit f9c0a8a

File tree

2 files changed

+47
-33
lines changed

2 files changed

+47
-33
lines changed

src/src/beneficiaries/beneficiaries.service.ts

Lines changed: 37 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { BeneficiariesCoreService } from './beneficiaries.core.service';
1919
import * as moment from 'moment';
2020
import { CSVHelperService } from 'src/helper/csvHelper.service';
2121
import { Method } from 'src/common/method/method';
22+
import { query } from 'express';
2223

2324
@Injectable()
2425
export class BeneficiariesService {
@@ -743,32 +744,36 @@ export class BeneficiariesService {
743744
let first_name = body.search.split(' ')[0];
744745
let last_name = body.search.split(' ')[1] || '';
745746

746-
if (last_name?.length > 0) {
747-
filterQueryArray.push(`{ _or: [
748-
{ first_name: { _ilike: "%${first_name}%" } },
749-
{ last_name: { _ilike: "%${last_name}%" } },
747+
if (/^\d+$/.test(body?.search)) {
748+
filterQueryArray.push(`{id: { _eq: "${body?.search}"} }`);
749+
} else {
750+
if (last_name?.length > 0) {
751+
filterQueryArray.push(`{ _or: [
752+
{ first_name: { _ilike: "%${first_name}%" } },
753+
{ last_name: { _ilike: "%${last_name}%" } },
754+
{
755+
program_beneficiaries: {
756+
_or: [
757+
{ enrollment_first_name: { _ilike: "%${first_name}%" } },
758+
{ enrollment_last_name: { _ilike: "%${last_name}%" } }
759+
]
760+
}
761+
}
762+
]} `);
763+
} else {
764+
filterQueryArray.push(`{_or: [
765+
{ first_name: { _ilike: "%${first_name}%" } }
766+
{ last_name: { _ilike: "%${first_name}%" } }
750767
{
751768
program_beneficiaries: {
752769
_or: [
753770
{ enrollment_first_name: { _ilike: "%${first_name}%" } },
754-
{ enrollment_last_name: { _ilike: "%${last_name}%" } }
771+
{ enrollment_last_name: { _ilike: "%${first_name}%" } }
755772
]
756773
}
757774
}
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-
}
775+
]} `);
770776
}
771-
]} `);
772777
}
773778
}
774779

@@ -900,6 +905,7 @@ export class BeneficiariesService {
900905
offset: offset,
901906
},
902907
};
908+
903909
const response = await this.hasuraServiceFromServices.getData(data);
904910
let mappedResponse = response?.data?.users;
905911
const count = response?.data?.users_aggregate?.aggregate?.count;
@@ -1002,16 +1008,20 @@ export class BeneficiariesService {
10021008
let first_name = body.search.split(' ')[0];
10031009
let last_name = body.search.split(' ')[1] || '';
10041010

1005-
if (last_name?.length > 0) {
1006-
filterQueryArray.push(`{_or: [
1007-
{ first_name: { _ilike: "%${first_name}%" } }
1008-
{ last_name: { _ilike: "%${last_name}%" } }
1009-
]} `);
1011+
if (/^\d+$/.test(body?.search)) {
1012+
filterQueryArray.push(`{id: { _eq: "${body?.search}"} }`);
10101013
} else {
1011-
filterQueryArray.push(`{_or: [
1012-
{ first_name: { _ilike: "%${first_name}%" } }
1013-
{ last_name: { _ilike: "%${first_name}%" } }
1014-
]} `);
1014+
if (last_name?.length > 0) {
1015+
filterQueryArray.push(`{_or: [
1016+
{ first_name: { _ilike: "%${first_name}%" } }
1017+
{ last_name: { _ilike: "%${last_name}%" } }
1018+
]} `);
1019+
} else {
1020+
filterQueryArray.push(`{_or: [
1021+
{ first_name: { _ilike: "%${first_name}%" } }
1022+
{ last_name: { _ilike: "%${first_name}%" } }
1023+
]} `);
1024+
}
10151025
}
10161026
}
10171027
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)