-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
248 additions
and
82 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,6 @@ | ||
import type { UpdateManyParams } from "react-admin"; | ||
|
||
// eslint-disable-next-line @typescript-eslint/require-await | ||
export const updateMany = async (resource: string, _: UpdateManyParams) => { | ||
switch (resource) { | ||
case "users": | ||
throw new Error("not implemented"); | ||
default: | ||
throw new Error(`unknown resource ${resource}`); | ||
} | ||
export const updateMany = async (_: string, __: UpdateManyParams) => { | ||
throw new Error("not implemented"); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
projects/server/prisma/migrations/20240108001454_/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Warnings: | ||
- Added the required column `endsAt` to the `Event` table without a default value. This is not possible if the table is not empty. | ||
- Added the required column `startsAt` to the `Event` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- CreateEnum | ||
CREATE TYPE "MarathonType" AS ENUM ('ONLINE', 'ONSITE'); | ||
|
||
-- AlterTable | ||
ALTER TABLE "Event" ADD COLUMN "endsAt" TIMESTAMP(3) NOT NULL, | ||
ADD COLUMN "published" BOOLEAN NOT NULL DEFAULT false, | ||
ADD COLUMN "startsAt" TIMESTAMP(3) NOT NULL; | ||
|
||
-- CreateTable | ||
CREATE TABLE "EventMarathonType" ( | ||
"id" UUID NOT NULL, | ||
"eventId" UUID NOT NULL, | ||
"marathonType" "MarathonType" NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
|
||
CONSTRAINT "EventMarathonType_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "EventMarathonType_eventId_marathonType_key" ON "EventMarathonType"("eventId", "marathonType"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "EventMarathonType" ADD CONSTRAINT "EventMarathonType_eventId_fkey" FOREIGN KEY ("eventId") REFERENCES "Event"("id") ON DELETE CASCADE ON UPDATE CASCADE; |
12 changes: 12 additions & 0 deletions
12
projects/server/prisma/migrations/20240109032853_/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
Warnings: | ||
- A unique constraint covering the columns `[username]` on the table `User` will be added. If there are existing duplicate values, this will fail. | ||
- Added the required column `username` to the `User` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "User" ADD COLUMN "username" VARCHAR(255) NOT NULL; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "User_username_key" ON "User"("username"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { z } from "zod"; | ||
import { prisma } from "../../prisma.js"; | ||
import { adminProcedure, router } from "../../trpc.js"; | ||
import { listSchema } from "./utils.js"; | ||
import { MarathonType } from "@prisma/client"; | ||
|
||
export const eventsRouter = router({ | ||
list: adminProcedure.input(listSchema).query(async ({ input }) => { | ||
const data = await prisma.event.findMany({ | ||
skip: input.skip, | ||
take: input.take, | ||
orderBy: { | ||
name: input.orderBy === "name" ? input.order : undefined, | ||
startsAt: input.orderBy === "startsAt" ? input.order : undefined, | ||
endsAt: input.orderBy === "endsAt" ? input.order : undefined, | ||
published: input.orderBy === "published" ? input.order : undefined, | ||
}, | ||
}); | ||
const count = await prisma.event.count(); | ||
return { data, count }; | ||
}), | ||
get: adminProcedure | ||
.input(z.object({ id: z.string().uuid() })) | ||
.query(async ({ input }) => { | ||
const event = await prisma.event.findUnique({ | ||
where: { | ||
id: input.id, | ||
}, | ||
}); | ||
if (!event) { | ||
throw new Error("event not found"); | ||
} | ||
return event; | ||
}), | ||
update: adminProcedure | ||
.input( | ||
z.object({ | ||
id: z.string().uuid(), | ||
data: z.object({ | ||
name: z.string(), | ||
startsAt: z.string(), | ||
endsAt: z.string(), | ||
published: z.boolean(), | ||
eventMarathonTypes: z.array( | ||
z.enum([MarathonType.ONLINE, MarathonType.ONSITE]), | ||
), | ||
}), | ||
}), | ||
) | ||
.mutation(async ({ input }) => { | ||
const event = await prisma.event.update({ | ||
where: { | ||
id: input.id, | ||
}, | ||
data: { | ||
name: input.data.name, | ||
startsAt: input.data.startsAt, | ||
endsAt: input.data.endsAt, | ||
published: input.data.published, | ||
}, | ||
}); | ||
return event; | ||
}), | ||
delete: adminProcedure | ||
.input(z.object({ id: z.string().uuid() })) | ||
.mutation(async ({ input }) => { | ||
const result = await prisma.event.delete({ | ||
where: { id: input.id }, | ||
}); | ||
return result; | ||
}), | ||
}); |
Oops, something went wrong.