v3: added comment likes, added votes/likes list view, added db migrations mechanism, updated project dependencies
All checks were successful
Build and Publish Docker Image / build-and-push (push) Successful in 42s

This commit is contained in:
khannurien
2026-06-21 14:17:56 +00:00
parent 888aae45cf
commit 7afb5d3f07
25 changed files with 1475 additions and 840 deletions

View File

@@ -1,5 +1,9 @@
import { APIErrorCode, APIException } from "../model/interfaces.ts";
import { db } from "../model/db.ts";
import {
APIErrorCode,
APIException,
type User,
} from "../model/interfaces.ts";
import { db, isUserRow, userRowToApi } from "../model/db.ts";
import { notifyDumpOwnerUpvote } from "./notification-service.ts";
export function castVote(dumpId: string, userId: string): number {
@@ -68,3 +72,36 @@ export function getUserVotes(userId: string): string[] {
).all(userId) as { dump_id: string }[];
return rows.map((r) => r.dump_id);
}
export function getDumpVoters(
dumpId: string,
page: number,
limit: number,
): { items: User[]; total: number } {
const offset = (page - 1) * limit;
const totalRow = db.prepare(
`SELECT COUNT(*) as count FROM votes WHERE dump_id = ?;`,
).get(dumpId) as { count: number } | undefined;
const rawRows = db.prepare(
`SELECT u.id, u.username, u.password_hash, u.is_admin, u.created_at, u.updated_at,
u.avatar_mime, u.description, u.invited_by, u.email,
i.username as invited_by_username
FROM users u
LEFT JOIN users i ON i.id = u.invited_by
INNER JOIN votes v ON v.dump_id = ? AND v.user_id = u.id
ORDER BY v.created_at DESC
LIMIT ? OFFSET ?;`,
).all(dumpId, limit, offset);
if (!rawRows.every(isUserRow)) {
throw new APIException(
APIErrorCode.SERVER_ERROR,
500,
"Malformed user data",
);
}
return { items: rawRows.map(userRowToApi), total: totalRow?.count ?? 0 };
}