feat: Implement chapter and lesson management with new services and types, and introduce Minio service.
This commit is contained in:
parent
40b95ad902
commit
6bbbde062a
8 changed files with 382 additions and 6 deletions
56
Backend/src/services/ChaptersLesson.service.ts
Normal file
56
Backend/src/services/ChaptersLesson.service.ts
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import { prisma } from '../config/database';
|
||||
import { Prisma } from '@prisma/client';
|
||||
import { config } from '../config';
|
||||
import { logger } from '../config/logger';
|
||||
import { UnauthorizedError, ValidationError, ForbiddenError, NotFoundError } from '../middleware/errorHandler';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import {
|
||||
LessonAttachmentData,
|
||||
LessonData,
|
||||
ChapterData,
|
||||
CreateLessonInput,
|
||||
UpdateLessonInput,
|
||||
CreateChapterInput,
|
||||
UpdateChapterInput,
|
||||
ChaptersRequest,
|
||||
DeleteChapterRequest,
|
||||
ReorderChapterRequest,
|
||||
ListChaptersResponse,
|
||||
GetChapterResponse,
|
||||
CreateChapterResponse,
|
||||
UpdateChapterResponse,
|
||||
DeleteChapterResponse,
|
||||
ReorderChapterResponse,
|
||||
ChapterWithLessonsResponse,
|
||||
ListLessonsRequest,
|
||||
GetLessonRequest,
|
||||
CreateLessonRequest,
|
||||
UpdateLessonRequest,
|
||||
DeleteLessonRequest,
|
||||
ReorderLessonsRequest,
|
||||
ListLessonsResponse,
|
||||
GetLessonResponse,
|
||||
CreateLessonResponse,
|
||||
UpdateLessonResponse,
|
||||
DeleteLessonResponse,
|
||||
ReorderLessonsResponse,
|
||||
} from "../types/ChaptersLesson.typs";
|
||||
|
||||
export class ChaptersLessonService {
|
||||
async listChapters(request: ChaptersRequest): Promise<ListChaptersResponse> {
|
||||
try {
|
||||
const { token, course_id } = request;
|
||||
const decodedToken = jwt.verify(token, config.jwt.secret) as { id: number };
|
||||
const user = await prisma.user.findUnique({ where: { id: decodedToken.id } });
|
||||
if (!user) {
|
||||
throw new UnauthorizedError('Invalid token');
|
||||
}
|
||||
const chapters = await prisma.chapter.findMany({ where: { course_id } });
|
||||
return { code: 200, message: 'Chapters fetched successfully', data: chapters as ChapterData[], total: chapters.length };
|
||||
} catch (error) {
|
||||
logger.error(`Error fetching chapters: ${error}`);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -143,7 +143,7 @@ export class CoursesInstructorService {
|
|||
|
||||
const course = await prisma.course.update({
|
||||
where: {
|
||||
id: courseInstructorId.user_id
|
||||
id: courseId
|
||||
},
|
||||
data: courseData
|
||||
});
|
||||
|
|
@ -167,7 +167,7 @@ export class CoursesInstructorService {
|
|||
|
||||
const course = await prisma.course.delete({
|
||||
where: {
|
||||
id: courseInstructorId.user_id
|
||||
id: courseId
|
||||
}
|
||||
});
|
||||
return {
|
||||
|
|
|
|||
0
Backend/src/services/Minio.service.ts
Normal file
0
Backend/src/services/Minio.service.ts
Normal file
|
|
@ -3,7 +3,7 @@ import { Prisma } from '@prisma/client';
|
|||
import { config } from '../config';
|
||||
import { logger } from '../config/logger';
|
||||
import jwt from 'jsonwebtoken';
|
||||
import { createCategory, createCategoryResponse, deleteCategoryResponse, updateCategory, updateCategoryResponse, listCategoriesResponse, Category } from '../types/categories.type';
|
||||
import { createCategory, createCategoryResponse, deleteCategoryResponse, updateCategory, updateCategoryResponse, listCategoriesResponse, Category } from '../types/Categories.type';
|
||||
import { UnauthorizedError, ValidationError, ForbiddenError } from '../middleware/errorHandler';
|
||||
|
||||
export class CategoryService {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { prisma } from '../config/database';
|
|||
import { Prisma } from '@prisma/client';
|
||||
import { config } from '../config';
|
||||
import { logger } from '../config/logger';
|
||||
import {listCourseResponse, getCourseResponse } from '../types/courses.types';
|
||||
import { listCourseResponse, getCourseResponse } from '../types/Courses.types';
|
||||
import { UnauthorizedError, ValidationError, ForbiddenError } from '../middleware/errorHandler';
|
||||
|
||||
export class CoursesService {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue