feat: add reviews, notifications, notes and account hardening
This commit is contained in:
@@ -420,3 +420,72 @@ export const getCommunityComments = async (limit = 100, offset = 0): Promise<Com
|
||||
const response = await apiRequest<{ data: ApiComment[] }>(`/community/comments?limit=${limit}&offset=${offset}`);
|
||||
return response.data.map(toComment);
|
||||
};
|
||||
|
||||
export type LearningStats = {
|
||||
watchedSeconds: number;
|
||||
completedLessons: number;
|
||||
activeCourses: number;
|
||||
weeklyCompleted: number;
|
||||
streakDays: number;
|
||||
};
|
||||
|
||||
export const getLearningStats = async (): Promise<LearningStats> => {
|
||||
const response = await apiRequest<{ data: LearningStats }>('/courses/me/learning/stats');
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export type CourseReview = {
|
||||
rating: number;
|
||||
comment: string;
|
||||
updatedAt: string;
|
||||
userName: string;
|
||||
};
|
||||
|
||||
export type MyCourseReview = {
|
||||
rating: number;
|
||||
comment: string;
|
||||
updatedAt: string;
|
||||
};
|
||||
|
||||
export type CourseReviewSummary = {
|
||||
average: number;
|
||||
count: number;
|
||||
reviews: CourseReview[];
|
||||
};
|
||||
|
||||
export const getCourseReviews = async (courseId: string): Promise<CourseReviewSummary> => {
|
||||
const response = await apiRequest<{ data: CourseReviewSummary }>(`/courses/${courseId}/reviews`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const getMyCourseReview = async (courseId: string): Promise<MyCourseReview | null> => {
|
||||
const response = await apiRequest<{ data: MyCourseReview | null }>(`/courses/${courseId}/reviews/mine`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const saveCourseReview = async (courseId: string, rating: number, comment: string): Promise<{ review: MyCourseReview; summary: CourseReviewSummary }> => {
|
||||
const response = await apiRequest<{ data: { review: MyCourseReview; summary: CourseReviewSummary } }>(`/courses/${courseId}/reviews/mine`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ rating, comment }),
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const deleteMyCourseReview = async (courseId: string): Promise<void> => {
|
||||
await apiRequest<void>(`/courses/${courseId}/reviews/mine`, { method: 'DELETE' });
|
||||
};
|
||||
|
||||
export type LessonNote = { body: string; updatedAt: string | null };
|
||||
|
||||
export const getLessonNote = async (lessonId: string): Promise<LessonNote> => {
|
||||
const response = await apiRequest<{ data: LessonNote }>(`/lessons/${lessonId}/note`);
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const saveLessonNote = async (lessonId: string, body: string): Promise<LessonNote> => {
|
||||
const response = await apiRequest<{ data: LessonNote }>(`/lessons/${lessonId}/note`, {
|
||||
method: 'PUT',
|
||||
body: JSON.stringify({ body }),
|
||||
});
|
||||
return response.data;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user