Skip to content

Commit

Permalink
Merge pull request #56 from Xitija/altv1
Browse files Browse the repository at this point in the history
Task #216125 : Search API with Grade
  • Loading branch information
snehal0904 authored Mar 21, 2024
2 parents 577d814 + fd4eb31 commit 052121b
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/adapters/hasura/altStudent.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,26 +451,33 @@ export class ALTStudentService {
offset = studentSearchDto.limit * (studentSearchDto.page - 1);
}

const limit = parseInt(studentSearchDto.limit)
? parseInt(studentSearchDto.limit)
: 10000;

let query = "";

Object.keys(studentSearchDto.filters).forEach((e) => {
if (studentSearchDto.filters[e] && studentSearchDto.filters[e] != "") {
if (e === "board") {
query += `${e}:{_ilike: "%${studentSearchDto.filters[e]?.ilike}%"}`;
} else {
} else if (
e === "grade" &&
parseInt(studentSearchDto.filters["grade"])
) {
query += `user: {GroupMemberships: {Group: {grade: {_eq: "${parseInt(
studentSearchDto.filters["grade"]
)}"}}}}`;
} else if (e !== "grade") {
query += `${e}:{_eq:"${studentSearchDto.filters[e]?.eq}"}`;
}
}
});

const data = {
query: `query SearchStudent($limit:Int, $offset:Int) {
Students_aggregate {
aggregate {
count
}
}
Students(where:{ ${query}}, limit: $limit, offset: $offset,) {
Students(where:{${query}}, limit: $limit, offset: $offset,) {
annualIncome
caste
schoolUdise
Expand Down Expand Up @@ -514,10 +521,11 @@ export class ALTStudentService {
}
}`,
variables: {
limit: parseInt(studentSearchDto.limit),
limit: limit,
offset: offset,
},
};

const config = {
method: "post",
url: this.baseURL,
Expand Down

0 comments on commit 052121b

Please sign in to comment.