Skip to content

Commit

Permalink
Search Query Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
amit-s19 committed Dec 28, 2023
1 parent 20beac4 commit d386da4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 60 deletions.
1 change: 1 addition & 0 deletions src/admin/admin.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export class AdminController {
@Get('/searchUser')
@Roles(
'Admin',
'super_admin_department',
'school',
'State Admin',
'District Admin',
Expand Down
115 changes: 55 additions & 60 deletions src/api/fusionauth/query-generator/query-generator.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,78 +2,73 @@ import { Injectable } from '@nestjs/common';

@Injectable()
export class QueryGeneratorService {
constructor(){}
constructor() { }

queryUsersByApplicationId(applicationId: string): string{
const query = {
bool: {
must: [
{
nested: {
path: "registrations",
query: {
bool: {
must: [
{
match: {
"registrations.applicationId": applicationId
}
}
]
queryUsersByApplicationId(applicationId: string): string {
const query = {
bool: {
must: [
{
nested: {
path: "registrations",
query: {
bool: {
must: [
{
match: {
"registrations.applicationId": applicationId
}
}
}
]
}
]
}
}
}
return JSON.stringify(query);
]
}
}
return JSON.stringify(query);
}

queryUsersByApplicationIdAndQueryString(applicationId: string[], queryString: string): string{
const query = {
bool: {
must: [
{
bool: {
must: [
[
{
nested: {
path: "registrations",
query: {
bool: {
should: this.createMatchTags(applicationId)
}
}
}
}
]
]
}
},
{
query_string: {
query: queryString
}
}
]
queryUsersByApplicationIdAndQueryString(applicationId: string[], queryString: string): string {
const query: any = {
"bool": {
"must": [{
"nested": {
"path": "registrations",
"query": {
"bool": {
"must": this.createMatchTags(applicationId)
}
}
}
return JSON.stringify(query)
}]
}
}

createMatchTags(arr: string[]): Array<{match: any}>{
let tags: Array<{match: any}> = [];
for(let x of arr){
tags.push(
{
match: {
"registrations.applicationId": x
}
}
)
if (queryString) {
query.bool.must.push(
{
"query_string": {
"query": queryString
}
})
}

return JSON.stringify(query)
}

createMatchTags(arr: string[]): Array<{ match: any }> {
let tags: Array<{ match: any }> = [];
for (let x of arr) {
tags.push(
{
match: {
"registrations.applicationId": x
}
}
return tags;
)
}
return tags;
}
}

0 comments on commit d386da4

Please sign in to comment.