initial commit ??
This commit is contained in:
35
src/lib/trpc/routers/presetdata.router.ts
Normal file
35
src/lib/trpc/routers/presetdata.router.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { dbPresetData } from "$lib/server/db/presetdata.db";
|
||||
import { zDDFilters, zPresetDataEntry } from "$lib/utils/data.types";
|
||||
import { z } from "zod";
|
||||
import { createTRPCRouter, protectedProcedure } from "../t";
|
||||
|
||||
export const presetDataRouter = createTRPCRouter({
|
||||
getAll: protectedProcedure.input(zDDFilters).mutation(async ({ input }) => {
|
||||
const { draw, date } = input;
|
||||
if (!draw) {
|
||||
return { ok: false, detail: "Draw is required to fetch data", data: [] };
|
||||
}
|
||||
return {
|
||||
data: await dbPresetData.getDataByDraw(date, +draw.id.split(":")[1]),
|
||||
ok: true,
|
||||
detail: "Data found",
|
||||
};
|
||||
}),
|
||||
|
||||
insert: protectedProcedure
|
||||
.input(z.array(zPresetDataEntry))
|
||||
.mutation(async ({ input }) => {
|
||||
return {
|
||||
ok: true,
|
||||
detail: "Data inserted",
|
||||
data: await dbPresetData.insertData(input),
|
||||
};
|
||||
}),
|
||||
|
||||
delete: protectedProcedure
|
||||
.input(z.object({ date: z.string(), ids: z.array(z.string()) }))
|
||||
.mutation(async ({ input }) => {
|
||||
await dbPresetData.deleteDataByIds(input.date, input.ids);
|
||||
return { ok: true, detail: "Data deleted" };
|
||||
}),
|
||||
});
|
||||
Reference in New Issue
Block a user