Skip to content

Commit 12553b9

Browse files
authored
Merge pull request #1532 from Tusharmahajan12/new_sep_search25
Customer Request #227746 [BE] Added search by ID in filter
2 parents 11489c9 + b57f4a9 commit 12553b9

File tree

1 file changed

+46
-55
lines changed

1 file changed

+46
-55
lines changed

src/src/program-coordinator/program-coordinator.service.ts

Lines changed: 46 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -184,14 +184,14 @@ export class ProgramCoordinatorService {
184184
) {
185185
return response.status(200).json({
186186
success: false,
187-
message: 'User already exists!',
188187
data: {},
188+
message: 'User already exists!',
189189
});
190190
} else {
191191
return response.status(200).json({
192192
success: false,
193-
message: registerUserRes.error.message,
194193
data: {},
194+
message: registerUserRes.error.message,
195195
});
196196
}
197197
} else if (registerUserRes.headers.location) {
@@ -306,13 +306,13 @@ export class ProgramCoordinatorService {
306306

307307
return response.status(200).send({
308308
success: true,
309-
message: 'User created successfully',
310309
data: {
311310
user: result?.data,
312311
keycloak_id: keycloak_id,
313312
username: data_to_create_user.username,
314313
password: password,
315314
},
315+
message: 'User created successfully',
316316
});
317317
} else {
318318
return response.status(200).json({
@@ -435,21 +435,18 @@ export class ProgramCoordinatorService {
435435
}
436436
let userFilter = [];
437437

438-
if (body?.search) {
439-
if (body.search) {
440-
let first_name = body.search.split(' ')[0];
441-
let last_name = body.search.split(' ')[1] || '';
442-
443-
if (last_name?.length > 0) {
444-
userFilter.push(`
445-
first_name: { _ilike: "%${first_name}%" },
446-
last_name: { _ilike: "%${last_name}%" }
447-
`);
448-
} else {
449-
userFilter.push(
450-
`first_name: { _ilike: "%${first_name}%" }`,
451-
);
452-
}
438+
if (body.search && body.search !== '') {
439+
let first_name = body.search.split(' ')[0];
440+
let last_name = body.search.split(' ')[1] || '';
441+
if (/^\d+$/.test(body.search)) {
442+
userFilter.push(`id: {_eq: ${body.search} }`);
443+
} else if (last_name?.length > 0) {
444+
userFilter.push(`
445+
first_name: { _ilike: "%${first_name}%" },
446+
last_name: { _ilike: "%${last_name}%" }
447+
`);
448+
} else {
449+
userFilter.push(`first_name: { _ilike: "%${first_name}%" }`);
453450
}
454451
}
455452

@@ -675,31 +672,28 @@ export class ProgramCoordinatorService {
675672
}
676673
let userFilter = [];
677674

678-
if (body?.search) {
679-
if (body.search) {
680-
let first_name = body.search.split(' ')[0];
681-
let last_name = body.search.split(' ')[1] || '';
682-
683-
if (last_name?.length > 0) {
684-
userFilter.push(`
675+
if (body.search && body.search !== '') {
676+
let first_name = body.search.split(' ')[0];
677+
let last_name = body.search.split(' ')[1] || '';
678+
if (/^\d+$/.test(body.search)) {
679+
userFilter.push(`id: {_eq: ${body.search} }`);
680+
} else if (last_name?.length > 0) {
681+
userFilter.push(`
685682
first_name: { _ilike: "%${first_name}%" },
686-
last_name: { _ilike: "%${last_name}%" }
687-
`);
688-
} else {
689-
userFilter.push(
690-
`first_name: { _ilike: "%${first_name}%" }`,
691-
);
692-
}
693-
}
694-
if (body.district) {
695-
userFilter.push(
696-
`district: {_in: ${JSON.stringify(body?.district)}}`,
697-
);
698-
}
699-
if (body.block) {
700-
userFilter.push(`block: {_in: ${JSON.stringify(body?.block)}}`);
683+
last_name: { _ilike: "%${last_name}%" }
684+
`);
685+
} else {
686+
userFilter.push(`first_name: { _ilike: "%${first_name}%" }`);
701687
}
702688
}
689+
if (body.district) {
690+
userFilter.push(
691+
`district: {_in: ${JSON.stringify(body?.district)}}`,
692+
);
693+
}
694+
if (body.block) {
695+
userFilter.push(`block: {_in: ${JSON.stringify(body?.block)}}`);
696+
}
703697

704698
if (userFilter.length > 0) {
705699
filter.push(`users: {${userFilter.join(', ')}}`);
@@ -841,21 +835,18 @@ export class ProgramCoordinatorService {
841835
//get list of available prerak list for given cohort.
842836
let userFilter = [];
843837

844-
if (body?.search) {
845-
if (body.search) {
846-
let first_name = body.search.split(' ')[0];
847-
let last_name = body.search.split(' ')[1] || '';
848-
849-
if (last_name?.length > 0) {
850-
userFilter.push(`
851-
first_name: { _ilike: "%${first_name}%" },
852-
last_name: { _ilike: "%${last_name}%" }
853-
`);
854-
} else {
855-
userFilter.push(
856-
`first_name: { _ilike: "%${first_name}%" }`,
857-
);
858-
}
838+
if (body.search && body.search !== '') {
839+
let first_name = body.search.split(' ')[0];
840+
let last_name = body.search.split(' ')[1] || '';
841+
if (/^\d+$/.test(body.search)) {
842+
userFilter.push(`id: {_eq: ${body.search} }`);
843+
} else if (last_name?.length > 0) {
844+
userFilter.push(`
845+
first_name: { _ilike: "%${first_name}%" },
846+
last_name: { _ilike: "%${last_name}%" }
847+
`);
848+
} else {
849+
userFilter.push(`first_name: { _ilike: "%${first_name}%" }`);
859850
}
860851
}
861852
if (body.district) {

0 commit comments

Comments
 (0)