v3: follows, notifications, invite-only registration, unread markers
This commit is contained in:
@@ -3,9 +3,10 @@ import {
|
||||
APIException,
|
||||
type Comment,
|
||||
} from "../model/interfaces.ts";
|
||||
import { type SQLOutputValue } from "node:sqlite";
|
||||
import {
|
||||
commentRowToApi,
|
||||
type CommentRow,
|
||||
commentRowToApi,
|
||||
db,
|
||||
isCommentRow,
|
||||
} from "../model/db.ts";
|
||||
@@ -18,7 +19,7 @@ function fetchComment(commentId: string): Comment {
|
||||
const row = db.prepare(
|
||||
`SELECT ${SELECT_COLS} FROM comments c JOIN users u ON c.user_id = u.id WHERE c.id = ?;`,
|
||||
).get(commentId);
|
||||
if (!row || !isCommentRow(row as Record<string, unknown>)) {
|
||||
if (!row || !isCommentRow(row as Record<string, SQLOutputValue>)) {
|
||||
throw new APIException(APIErrorCode.NOT_FOUND, 404, "Comment not found");
|
||||
}
|
||||
return commentRowToApi(row as CommentRow);
|
||||
@@ -50,7 +51,14 @@ export function createComment(
|
||||
const createdAt = new Date();
|
||||
db.prepare(
|
||||
`INSERT INTO comments (id, dump_id, user_id, parent_id, body, created_at) VALUES (?, ?, ?, ?, ?, ?);`,
|
||||
).run(id, dumpId, userId, parentId ?? null, body.trim(), createdAt.toISOString());
|
||||
).run(
|
||||
id,
|
||||
dumpId,
|
||||
userId,
|
||||
parentId ?? null,
|
||||
body.trim(),
|
||||
createdAt.toISOString(),
|
||||
);
|
||||
return fetchComment(id);
|
||||
}
|
||||
|
||||
@@ -73,6 +81,8 @@ export function deleteComment(
|
||||
"Not authorized to delete this comment",
|
||||
);
|
||||
}
|
||||
db.prepare(`UPDATE comments SET deleted = 1, body = '' WHERE id = ?;`).run(commentId);
|
||||
db.prepare(`UPDATE comments SET deleted = 1, body = '' WHERE id = ?;`).run(
|
||||
commentId,
|
||||
);
|
||||
return { dumpId: row.dump_id, isPrivate: Boolean(row.is_private) };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user