Skip to content

Commit

Permalink
events
Browse files Browse the repository at this point in the history
  • Loading branch information
Hoishin committed Jan 10, 2024
1 parent 3e97f98 commit 1064609
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
3 changes: 2 additions & 1 deletion projects/admin/src/app.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Admin, Resource } from "react-admin";
import { Admin, ListGuesser, Resource } from "react-admin";
import { dataProvider } from "./data-provider/data-provider";
import { UserEdit, UserList } from "./users";
import { LoginPage } from "./login";
Expand All @@ -17,6 +17,7 @@ export const App = () => {
edit={UserEdit}
recordRepresentation="email"
/>
<Resource name="events" list={ListGuesser} />
</Admin>
);
};
15 changes: 14 additions & 1 deletion projects/admin/src/data-provider/create.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
/* eslint-disable @typescript-eslint/require-await */
import type { CreateParams, CreateResult } from "react-admin";
import { trpc } from "../trpc";
import { z } from "zod";

const createEventSchema = z.object({
name: z.string(),
startsAt: z.string().datetime(),
endsAt: z.string().datetime(),
});

export const create = async (
resource: string,
_: CreateParams,
params: CreateParams,
): Promise<CreateResult> => {
switch (resource) {
case "users":
throw new Error("not allowed");
case "events": {
const input = createEventSchema.parse(params.data);
const res = await trpc.admin.events.create.mutate(input);
return { data: res };
}
default:
throw new Error(`unknown resource ${resource}`);
}
Expand Down
2 changes: 2 additions & 0 deletions projects/server/src/routes/admin.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { router } from "../trpc.js";
import { eventsRouter } from "./admin/events.js";
import { usersRouter } from "./admin/users.js";

export const adminRouter = router({
users: usersRouter,
events: eventsRouter,
});
24 changes: 24 additions & 0 deletions projects/server/src/routes/admin/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ export const eventsRouter = router({
}
return event;
}),
create: adminProcedure
.input(
z.object({
name: z.string(),
startsAt: z
.string()
.datetime()
.transform((date) => new Date(date)),
endsAt: z
.string()
.datetime()
.transform((date) => new Date(date)),
}),
)
.mutation(async ({ input }) => {
const event = await prisma.event.create({
data: {
name: input.name,
startsAt: input.startsAt,
endsAt: input.endsAt,
},
});
return event;
}),
update: adminProcedure
.input(
z.object({
Expand Down

0 comments on commit 1064609

Please sign in to comment.