add filter to course

This commit is contained in:
JakkrapartXD 2026-01-23 10:37:19 +07:00
parent 1cbaed72cb
commit 5e7d265ffb
2 changed files with 16 additions and 5 deletions

View file

@ -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',