feat: add reviews, notifications, notes and account hardening
This commit is contained in:
@@ -220,6 +220,9 @@ export const authApi = {
|
||||
async resetPassword(token: string, password: string) {
|
||||
return apiRequest<void>('/auth/reset-password', { method: 'POST', body: JSON.stringify({ token, password }) });
|
||||
},
|
||||
async forgotPassword(email: string) {
|
||||
return apiRequest<void>('/auth/forgot-password', { method: 'POST', body: JSON.stringify({ email }) });
|
||||
},
|
||||
};
|
||||
|
||||
export const adminApi = {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
29
services/notifications.ts
Normal file
29
services/notifications.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import { apiRequest } from './api';
|
||||
|
||||
export type NotificationItem = {
|
||||
id: string;
|
||||
kind: string;
|
||||
title: string;
|
||||
body: string;
|
||||
href: string;
|
||||
readAt: string | null;
|
||||
createdAt: string;
|
||||
};
|
||||
|
||||
export type NotificationFeed = {
|
||||
items: NotificationItem[];
|
||||
unread: number;
|
||||
};
|
||||
|
||||
export const getNotifications = async (): Promise<NotificationFeed> => {
|
||||
const response = await apiRequest<{ data: NotificationFeed }>('/notifications');
|
||||
return response.data;
|
||||
};
|
||||
|
||||
export const markNotificationRead = async (notificationId: string): Promise<void> => {
|
||||
await apiRequest<void>(`/notifications/${notificationId}/read`, { method: 'POST' });
|
||||
};
|
||||
|
||||
export const markAllNotificationsRead = async (): Promise<void> => {
|
||||
await apiRequest<void>('/notifications/read-all', { method: 'POST' });
|
||||
};
|
||||
Reference in New Issue
Block a user