From 26e39b8dd492e9c4f1d5b6ed30cd5e9ed6f6926f Mon Sep 17 00:00:00 2001 From: sukanyamohanty143 Date: Tue, 8 Oct 2024 13:25:45 +0530 Subject: [PATCH] Add search functionality in instructor class recoding. --- src/controller/instructor/instructor.controller.ts | 10 +++++++++- src/controller/instructor/instructor.service.ts | 13 ++++++++++--- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/controller/instructor/instructor.controller.ts b/src/controller/instructor/instructor.controller.ts index 7887bd25..d5d3010e 100644 --- a/src/controller/instructor/instructor.controller.ts +++ b/src/controller/instructor/instructor.controller.ts @@ -150,6 +150,12 @@ 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, @@ -157,6 +163,7 @@ import { ErrorResponse, SuccessResponse } from 'src/errorHandler/handler'; @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 ){ @@ -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) diff --git a/src/controller/instructor/instructor.service.ts b/src/controller/instructor/instructor.service.ts index dbd1c0f4..49d894cb 100644 --- a/src/controller/instructor/instructor.service.ts +++ b/src/controller/instructor/instructor.service.ts @@ -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: { @@ -210,7 +211,9 @@ export class InstructorService { offset: number, weeks: number, sortBy: string, - batchId:number[]):Promise + batchId:number[], + searchTitle: string, + ):Promise { try { let startDate: string | undefined; @@ -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 : {