feat: Add token-based authorization to category deletion and enhance user registration with error handling and audit logging.
This commit is contained in:
parent
11f9ad57cd
commit
bb38c0f3c9
16 changed files with 1202 additions and 237 deletions
|
|
@ -142,6 +142,17 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Chapter created successfully', data: chapter as ChapterData };
|
||||
} catch (error) {
|
||||
logger.error(`Error creating chapter: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Chapter',
|
||||
entityId: 0,
|
||||
metadata: {
|
||||
operation: 'create_chapter',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -163,6 +174,17 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Chapter updated successfully', data: chapter as ChapterData };
|
||||
} catch (error) {
|
||||
logger.error(`Error updating chapter: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Chapter',
|
||||
entityId: request.chapter_id,
|
||||
metadata: {
|
||||
operation: 'update_chapter',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -197,6 +219,17 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Chapter deleted successfully' };
|
||||
} catch (error) {
|
||||
logger.error(`Error deleting chapter: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Chapter',
|
||||
entityId: request.chapter_id,
|
||||
metadata: {
|
||||
operation: 'delete_chapter',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -280,6 +313,17 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Chapter reordered successfully', data: chapters as ChapterData[] };
|
||||
} catch (error) {
|
||||
logger.error(`Error reordering chapter: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Chapter',
|
||||
entityId: request.chapter_id,
|
||||
metadata: {
|
||||
operation: 'reorder_chapter',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -354,6 +398,17 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Lesson created successfully', data: lesson as LessonData };
|
||||
} catch (error) {
|
||||
logger.error(`Error creating lesson: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: 0,
|
||||
metadata: {
|
||||
operation: 'create_lesson',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -494,6 +549,17 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Lesson fetched successfully', data: lessonData as LessonData };
|
||||
} catch (error) {
|
||||
logger.error(`Error fetching lesson: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: request.lesson_id,
|
||||
metadata: {
|
||||
operation: 'get_lesson',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -515,6 +581,17 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Lesson updated successfully', data: lesson as LessonData };
|
||||
} catch (error) {
|
||||
logger.error(`Error updating lesson: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: request.lesson_id,
|
||||
metadata: {
|
||||
operation: 'update_lesson',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -605,6 +682,17 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Lessons reordered successfully', data: lessons as LessonData[] };
|
||||
} catch (error) {
|
||||
logger.error(`Error reordering lessons: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: request.lesson_id,
|
||||
metadata: {
|
||||
operation: 'reorder_lessons',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -676,6 +764,17 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Lesson deleted successfully' };
|
||||
} catch (error) {
|
||||
logger.error(`Error deleting lesson: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: request.lesson_id,
|
||||
metadata: {
|
||||
operation: 'delete_lesson',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -754,6 +853,17 @@ export class ChaptersLessonService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error uploading video: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: request.lesson_id,
|
||||
metadata: {
|
||||
operation: 'upload_video',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -836,6 +946,17 @@ export class ChaptersLessonService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error updating video: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: request.lesson_id,
|
||||
metadata: {
|
||||
operation: 'update_video',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -917,6 +1038,17 @@ export class ChaptersLessonService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error setting YouTube video: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Lesson',
|
||||
entityId: request.lesson_id,
|
||||
metadata: {
|
||||
operation: 'set_youtube_video',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -993,6 +1125,17 @@ export class ChaptersLessonService {
|
|||
};
|
||||
} catch (error) {
|
||||
logger.error(`Error uploading attachment: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'LessonAttachment',
|
||||
entityId: request.lesson_id,
|
||||
metadata: {
|
||||
operation: 'upload_attachment',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -1051,6 +1194,17 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Attachment deleted successfully' };
|
||||
} catch (error) {
|
||||
logger.error(`Error deleting attachment: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'LessonAttachment',
|
||||
entityId: request.attachment_id,
|
||||
metadata: {
|
||||
operation: 'delete_attachment',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -1127,6 +1281,17 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Question added successfully', data: completeQuestion as QuizQuestionData };
|
||||
} catch (error) {
|
||||
logger.error(`Error adding question: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Question',
|
||||
entityId: 0,
|
||||
metadata: {
|
||||
operation: 'add_question',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -1202,6 +1367,17 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Question updated successfully', data: completeQuestion as QuizQuestionData };
|
||||
} catch (error) {
|
||||
logger.error(`Error updating question: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Question',
|
||||
entityId: request.question_id,
|
||||
metadata: {
|
||||
operation: 'update_question',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -1295,6 +1471,17 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Question reordered successfully', data: questions as QuizQuestionData[] };
|
||||
} catch (error) {
|
||||
logger.error(`Error reordering question: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Question',
|
||||
entityId: request.question_id,
|
||||
metadata: {
|
||||
operation: 'reorder_question',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
@ -1343,6 +1530,17 @@ export class ChaptersLessonService {
|
|||
return { code: 200, message: 'Question deleted successfully' };
|
||||
} catch (error) {
|
||||
logger.error(`Error deleting question: ${error}`);
|
||||
const decodedToken = jwt.decode(request.token) as { id: number } | null;
|
||||
await auditService.logSync({
|
||||
userId: decodedToken?.id || 0,
|
||||
action: AuditAction.ERROR,
|
||||
entityType: 'Question',
|
||||
entityId: request.question_id,
|
||||
metadata: {
|
||||
operation: 'delete_question',
|
||||
error: error instanceof Error ? error.message : String(error)
|
||||
}
|
||||
});
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue