AcadeDoc/apps/client/src/features/acadenice/comments/services/row-comments-client.ts
Corentin a39c158748 refactor(acadedoc): audit REST conventions + fix pre-existing tests — R5.2
BREAKING CHANGES (row-comments routes):
- POST /v1/row-comments/list     → GET  /v1/row-comments (query params)
- POST /v1/row-comments/create   → POST /v1/row-comments (201 Created)
- POST /v1/row-comments/update   → PATCH /v1/row-comments/:id
- POST /v1/row-comments/resolve  → PATCH /v1/row-comments/:id/resolve
- POST /v1/row-comments/delete   → DELETE /v1/row-comments/:id (204)
- POST /v1/row-comments/count    → GET /v1/row-comments/count (query params)
- UpdateRowCommentDto/ResolveRowCommentDto: removed commentId field (now path param)

REST patches (non-breaking):
- POST /v1/sync-blocks: added explicit @HttpCode(201)
- POST /v1/slash-commands: added explicit @HttpCode(201)
- POST /v1/templates: added explicit @HttpCode(201)
- POST /v1/templates/:id/instantiate: added explicit @HttpCode(201)

Pre-existing test fixes:
- clipper-client.test.ts: jest.mock/jest.fn → vi.mock/vi.fn (Vitest compat)
- templates-client.ts + clipper-client.ts + slash-commands-client.ts
  + sync-blocks-client.ts: removed double-unwrap .data.data → .data

Tests: 366/366 client vitest pass, 448/453 server jest pass (5 pre-existing infra failures)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-08 15:33:54 +02:00

80 lines
1.9 KiB
TypeScript

import api from "@/lib/api-client";
export interface RowComment {
id: string;
workspaceId: string;
tableId: string;
rowId: string;
parentCommentId: string | null;
content: Record<string, unknown>;
authorUserId: string;
isResolved: boolean;
resolvedAt: string | null;
resolvedBy: string | null;
createdAt: string;
updatedAt: string;
author?: { id: string; name: string; avatarUrl: string | null };
resolver?: { id: string; name: string; avatarUrl: string | null };
}
export interface ListRowCommentsParams {
tableId: string;
rowId: string;
resolved?: boolean;
}
export interface CreateRowCommentParams {
tableId: string;
rowId: string;
content: string;
parentCommentId?: string;
}
export async function listRowComments(
params: ListRowCommentsParams,
): Promise<RowComment[]> {
const res = await api.get<RowComment[]>("/v1/row-comments", { params });
return res.data;
}
export async function createRowComment(
params: CreateRowCommentParams,
): Promise<RowComment> {
const res = await api.post<RowComment>("/v1/row-comments", params);
return res.data;
}
export async function updateRowComment(
commentId: string,
content: string,
): Promise<RowComment> {
const res = await api.patch<RowComment>(`/v1/row-comments/${commentId}`, {
content,
});
return res.data;
}
export async function resolveRowComment(
commentId: string,
resolved: boolean,
): Promise<RowComment> {
const res = await api.patch<RowComment>(
`/v1/row-comments/${commentId}/resolve`,
{ resolved },
);
return res.data;
}
export async function deleteRowComment(commentId: string): Promise<void> {
await api.delete(`/v1/row-comments/${commentId}`);
}
export async function countRowComments(
tableId: string,
rowId: string,
): Promise<number> {
const res = await api.get<{ count: number }>("/v1/row-comments/count", {
params: { tableId, rowId },
});
return res.data.count;
}