Skip to content

Commit 62dcc3a

Browse files
committed
add server action to save users record
1 parent 19248e4 commit 62dcc3a

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/app/_actions/result.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"use server";
2+
3+
import { User } from "@prisma/client";
4+
import { prisma } from "@/lib/prisma";
5+
6+
export async function saveUserResult(input: {
7+
userId: User["id"];
8+
timeTaken: string | number;
9+
}) {
10+
if (typeof input.timeTaken !== "string" && typeof input.timeTaken !== "number") {
11+
throw new Error("Invalid input.");
12+
}
13+
14+
await prisma.result.create({
15+
data: {
16+
userId: input.userId,
17+
takenTime: input.timeTaken.toString(),
18+
},
19+
});
20+
}

0 commit comments

Comments
 (0)