-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #37 from abinth11/features-students-course-search-…
…filter Features students course search filter
- Loading branch information
Showing
14 changed files
with
325 additions
and
109 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { CourseDbRepositoryInterface } from '../../../app/repositories/courseDbRepository'; | ||
import AppError from '../../../utils/appError'; | ||
import HttpStatusCodes from '../../../constants/HttpStatusCodes'; | ||
import { CourseInterface } from '../../../types/courseInterface'; | ||
import { CloudServiceInterface } from '@src/app/services/cloudServiceInterface'; | ||
|
||
export const searchCourseU = async ( | ||
searchQuery: string, | ||
filterQuery: string, | ||
cloudService:ReturnType<CloudServiceInterface>, | ||
courseDbRepository: ReturnType<CourseDbRepositoryInterface> | ||
) => { | ||
if (!searchQuery && !filterQuery) { | ||
throw new AppError( | ||
'Please provide a search or filter query', | ||
HttpStatusCodes.BAD_REQUEST | ||
); | ||
} | ||
let isFree = false | ||
let searchParams: string; | ||
|
||
if (searchQuery) { | ||
// Check if the search query has the "free" prefix | ||
const freeRegex = /^free\s/i; | ||
const isFreeMatch = searchQuery.match(freeRegex); | ||
if (isFreeMatch) { | ||
isFree = true; | ||
searchParams = searchQuery.replace(freeRegex, '').trim(); | ||
} else { | ||
searchParams = searchQuery; | ||
} | ||
} else { | ||
searchParams = filterQuery; | ||
} | ||
|
||
const searchResult= await courseDbRepository.searchCourse( | ||
isFree, | ||
searchParams, | ||
filterQuery | ||
); | ||
await Promise.all( | ||
searchResult.map(async (course) => { | ||
if (course.thumbnail) { | ||
course.thumbnailUrl = await cloudService.getFile(course.thumbnail.key); | ||
} | ||
}) | ||
); | ||
return searchResult; | ||
}; |
Oops, something went wrong.