forked from codechefPesuecc/CodeChef-PESUECC-Chapter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolves.ts
More file actions
28 lines (27 loc) · 778 Bytes
/
Copy pathsolves.ts
File metadata and controls
28 lines (27 loc) · 778 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { and, eq } from "drizzle-orm";
import { getDb } from "@/server/db";
import { submissions } from "@/server/db/schema";
/**
* Whether a user has a live (ranked) accepted solve for a problem. Backs both the
* hide-after-solve gate on the solve page and the one-solve guard in the submit
* route, so the two can't disagree.
*/
export async function hasSolvedRanked(
userId: string,
slug: string,
): Promise<boolean> {
const db = getDb();
const rows = await db
.select({ id: submissions.id })
.from(submissions)
.where(
and(
eq(submissions.userId, userId),
eq(submissions.challengeSlug, slug),
eq(submissions.status, "AC"),
eq(submissions.ranked, true),
),
)
.limit(1);
return rows.length > 0;
}