Skip to content

Commit

Permalink
Add search functionality in instructor class recoding.
Browse files Browse the repository at this point in the history
  • Loading branch information
sukanyamohanty143 committed Oct 8, 2024
1 parent b24154b commit 26e39b8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/controller/instructor/instructor.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,20 @@ import { ErrorResponse, SuccessResponse } from 'src/errorHandler/handler';
type: String,
description: 'Sort the classes ascending or descending',
})
@ApiQuery({
name: 'searchTitle',
required: false,
type: String,
description: 'Search by title',
})
@ApiBearerAuth()
async getAllCompletedClasses(
@Query('limit') limit: number,
@Query('offset') offset: number,
@Query('weeks') weeks: number,
@Query('sortBy') sortBy: string,
@Query('batchId', new ParseArrayPipe({ items: Number, optional: true })) batchId: number[] = [],
@Query('searchTitle') searchTitle: string,
@Req() req,
@Res() res
){
Expand All @@ -167,7 +174,8 @@ import { ErrorResponse, SuccessResponse } from 'src/errorHandler/handler';
offset,
weeks,
sortBy,
batchId
batchId,
searchTitle
);
if (err) {
return ErrorResponse.BadRequestException(err.message, err.statusCode).send(res)
Expand Down
13 changes: 10 additions & 3 deletions src/controller/instructor/instructor.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ export class InstructorService {
const data = await db.query.zuvyBootcamps.findMany({
columns: {
id: true,
name: true
name: true,
coverImage: true
},
with: {
batches: {
Expand Down Expand Up @@ -210,7 +211,9 @@ export class InstructorService {
offset: number,
weeks: number,
sortBy: string,
batchId:number[]):Promise<any>
batchId:number[],
searchTitle: string,
):Promise<any>
{
try {
let startDate: string | undefined;
Expand All @@ -230,7 +233,11 @@ export class InstructorService {
}
}
const classDetails = await db.query.zuvySessions.findMany({
where: (sessions, { lt, gte }) =>and( lt(sessions.endTime, helperVariable.currentISOTime), startDate ? gte(sessions.endTime, startDate) : undefined,inArray(sessions.batchId,batches) ),
where: (sessions, { lt, gte }) =>and( lt(sessions.endTime, helperVariable.currentISOTime), startDate ? gte(sessions.endTime, startDate) : undefined,inArray(sessions.batchId,batches),
searchTitle
? sql`LOWER(${sessions.title}) LIKE LOWER(${sql.raw(`'${searchTitle}%'`)})`
: undefined
),
orderBy: (sessions, { asc, desc }) =>
sortBy === 'asc' ? asc(sessions.startTime) : desc(sessions.startTime),
with : {
Expand Down

0 comments on commit 26e39b8

Please sign in to comment.