mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 02:32:57 +00:00
77 lines
2.3 KiB
TypeScript
77 lines
2.3 KiB
TypeScript
import api from './api';
|
|
|
|
export type TargetType = 'article' | 'event' | 'gallery_album' | 'youtube_video';
|
|
|
|
export type CommentItem = {
|
|
id: number;
|
|
target_type: TargetType;
|
|
target_id: string;
|
|
target_label?: string;
|
|
parent_id?: number | null;
|
|
content: string;
|
|
content_html?: string;
|
|
status?: 'visible' | 'hidden';
|
|
is_edited?: boolean;
|
|
edited_at?: string | null;
|
|
created_at: string;
|
|
updated_at: string;
|
|
reactions?: Record<string, number>;
|
|
my_reaction?: string;
|
|
admin_liked?: boolean;
|
|
user: {
|
|
id: number;
|
|
first_name?: string;
|
|
last_name?: string;
|
|
role?: string;
|
|
username?: string;
|
|
avatar_url?: string;
|
|
};
|
|
};
|
|
|
|
export type CommentsResponse = {
|
|
items: CommentItem[];
|
|
total: number;
|
|
page: number;
|
|
page_size: number;
|
|
};
|
|
|
|
export async function listComments(params: { target_type: TargetType; target_id: string; page?: number; page_size?: number; }): Promise<CommentsResponse> {
|
|
const res = await api.get('/comments', { params });
|
|
return res.data as CommentsResponse;
|
|
}
|
|
|
|
export async function createComment(body: { target_type: TargetType; target_id: string; content: string; parent_id?: number | null; }): Promise<CommentItem> {
|
|
const res = await api.post('/comments', body);
|
|
return res.data as CommentItem;
|
|
}
|
|
|
|
export async function updateComment(id: number, body: { content: string; }): Promise<CommentItem> {
|
|
const res = await api.put(`/comments/${id}`, body);
|
|
return res.data as CommentItem;
|
|
}
|
|
|
|
export async function deleteComment(id: number): Promise<{ ok: boolean }>{
|
|
const res = await api.delete(`/comments/${id}`);
|
|
return res.data as { ok: boolean };
|
|
}
|
|
|
|
export async function reactComment(id: number, type: string): Promise<{ ok: boolean }>{
|
|
const res = await api.post(`/comments/${id}/react`, { type });
|
|
return res.data as { ok: boolean };
|
|
}
|
|
|
|
export async function unreactComment(id: number): Promise<{ ok: boolean }>{
|
|
const res = await api.delete(`/comments/${id}/react`);
|
|
return res.data as { ok: boolean };
|
|
}
|
|
|
|
export async function requestUnban(message: string): Promise<{ ok: boolean }>{
|
|
const res = await api.post('/comments/unban-request', { message });
|
|
return res.data as { ok: boolean };
|
|
}
|
|
|
|
export async function reportComment(id: number, reason?: string): Promise<{ ok: boolean }>{
|
|
const res = await api.post(`/comments/${id}/report`, { reason });
|
|
return res.data as { ok: boolean };
|
|
}
|