add filter to course
This commit is contained in:
parent
1cbaed72cb
commit
5e7d265ffb
2 changed files with 16 additions and 5 deletions
|
|
@ -6,9 +6,15 @@ import { listCourseResponse, getCourseResponse } from '../types/courses.types';
|
|||
import { UnauthorizedError, ValidationError, ForbiddenError } from '../middleware/errorHandler';
|
||||
|
||||
export class CoursesService {
|
||||
async ListCourses(): Promise<listCourseResponse> {
|
||||
async ListCourses(category_id?: number): Promise<listCourseResponse> {
|
||||
try {
|
||||
const courses = await prisma.course.findMany();
|
||||
const where: Prisma.CourseWhereInput = {};
|
||||
|
||||
if (category_id) {
|
||||
where.category_id = category_id;
|
||||
}
|
||||
|
||||
const courses = await prisma.course.findMany({ where });
|
||||
return {
|
||||
code: 200,
|
||||
message: 'Courses fetched successfully',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue