Move from TRPC to server actions

This commit is contained in:
Timothy Armes
2024-04-08 14:55:06 +02:00
parent cd83db2385
commit 0540ecc05a
25 changed files with 1802 additions and 1774 deletions
+45
View File
@@ -0,0 +1,45 @@
"use server";
import { z } from "zod";
import clientPromise from "@/lib/mongodb";
import { TournamentData } from "@/types";
import { TimeControl, tcMap } from "@/types";
import { errorLog } from "@/utils/logger";
import { action } from "./safeAction";
const inputSchema = z.object({
ffeId: z.string(),
});
export const getTournamentDetails = action(inputSchema, async (input) => {
try {
const client = await clientPromise;
const db = client.db("tournamentsFranceDB");
const t = await db
.collection("tournaments")
.findOne<TournamentData>({ tournament_id: input.ffeId });
if (t === null) {
return null;
}
const timeControl = tcMap[t.time_control] ?? TimeControl.Other;
return {
id: t._id.toString(),
ffeId: t.tournament_id,
tournament: t.tournament,
town: t.town,
department: t.department,
date: t.date,
url: t.url,
timeControl,
status: t.status,
};
} catch (error) {
errorLog(JSON.stringify(error, null, 2));
throw error;
}
});