Skip to content

Commit

Permalink
update schema and add party routes
Browse files Browse the repository at this point in the history
  • Loading branch information
minhd-vu committed Feb 10, 2024
1 parent 96dc020 commit bdaa654
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 7 deletions.
30 changes: 27 additions & 3 deletions nextjs/app/api/party/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import prisma from "@/lib/prisma";
import { Mode, Party } from "@prisma/client";
import { customAlphabet } from "nanoid";
import { getServerSession } from "next-auth";

Expand All @@ -9,14 +11,36 @@ export async function GET() {
return Response.json(null, { status: 401 });
}

return Response.json(null);
const user = await prisma.user.findUnique({
where: {
email: session.user.email,
},
include: {
party: {
include: {
winner: true,
players: true,
},
},
},
});

return Response.json(user);
}

export async function POST(req: Request) {
export async function POST() {
const session = await getServerSession();
if (!session || !session.user) {
return Response.json(null, { status: 401 });
}

return Response.json(null);
const code = nanoid();
const party = await prisma.party.create({
data: {
code: code,
mode: Mode.CLASSIC,
} as Party,
});

return Response.json(party);
}
15 changes: 11 additions & 4 deletions nextjs/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ model User {
pending Boolean @default(false)
admin Boolean @default(false)
party Party? @relation("PartyPlayers", fields: [partyId], references: [id])
partyId String? @map("party_id") @db.ObjectId
targetId String? @map("target_id") @db.ObjectId
party Party? @relation("PartyPlayers", fields: [partyId], references: [id])
partyId String? @map("party_id") @db.ObjectId
target User? @relation("UserTarget", fields: [targetId], references: [id], onDelete: NoAction, onUpdate: NoAction)
targetId String? @map("target_id") @db.ObjectId
targetedBy User[] @relation("UserTarget")
parties Party[]
@@map("users")
}
Expand All @@ -29,7 +34,9 @@ model Party {
started Boolean @default(false)
mode Mode @default(CLASSIC)
players User[] @relation("PartyPlayers")
players User[] @relation("PartyPlayers")
winner User? @relation(fields: [winnerId], references: [id], onDelete: NoAction, onUpdate: NoAction)
winnerId String? @map("winner_id") @db.ObjectId
@@map("parties")
Expand Down

0 comments on commit bdaa654

Please sign in to comment.