init
This commit is contained in:
43
src/features/tournaments/server.ts
Normal file
43
src/features/tournaments/server.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { superTokensAdminFunctionMiddleware, superTokensFunctionMiddleware } from "@/utils/supertokens";
|
||||
import { createServerFn } from "@tanstack/react-start";
|
||||
import { pbAdmin } from "@/lib/pocketbase/client";
|
||||
import { tournamentInputSchema } from "@/features/tournaments/types";
|
||||
import { logger } from ".";
|
||||
import { z } from "zod";
|
||||
|
||||
export const listTournaments = createServerFn()
|
||||
.middleware([superTokensFunctionMiddleware])
|
||||
.handler(async () => {
|
||||
try {
|
||||
const result = await pbAdmin.listTournaments();
|
||||
return result;
|
||||
} catch (error) {
|
||||
logger.error('Error fetching tournaments', error);
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
export const createTournament = createServerFn()
|
||||
.validator(tournamentInputSchema)
|
||||
.middleware([superTokensAdminFunctionMiddleware])
|
||||
.handler(async ({ data }) => {
|
||||
try {
|
||||
logger.info('Creating tournament', data);
|
||||
|
||||
const tournament = await pbAdmin.createTournament(data);
|
||||
|
||||
return tournament;
|
||||
} catch (error) {
|
||||
logger.error('Error creating tournament', error);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
export const getTournament = createServerFn()
|
||||
.validator(z.string())
|
||||
.middleware([superTokensFunctionMiddleware])
|
||||
.handler(async ({ data: tournamentId }) => {
|
||||
logger.info('Getting tournament', tournamentId);
|
||||
const tournament = await pbAdmin.getTournament(tournamentId);
|
||||
return tournament;
|
||||
});
|
||||
Reference in New Issue
Block a user