fjzon
fjzon
TTCTheo's Typesafe Cult
Created by fjzon on 4/24/2023 in #questions
How to model my Prisma for a Golf-application
I have this golf application where all Users have their own bags. Inside their bags they have several Golf clubs. I want to fetch their bags and also list out all the golf clubs inside their respective bags.
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
role Role @default(USER)
bags Bag[]
}

model Bag {
id String @id @default(cuid())
name String
description String?
clubs GolfClub[]
active Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String

@@index([userId])
}

model GolfClub {
id String @id @default(cuid())
name String
description String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
bag Bag[]
bagId String?

@@index([bagId])
}
model User {
id String @id @default(cuid())
name String?
email String? @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
role Role @default(USER)
bags Bag[]
}

model Bag {
id String @id @default(cuid())
name String
description String?
clubs GolfClub[]
active Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
userId String

@@index([userId])
}

model GolfClub {
id String @id @default(cuid())
name String
description String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
bag Bag[]
bagId String?

@@index([bagId])
}
How could I achieve this? I guess I can't look inside the bag and see what clubs there is inside there. That instead, I'll have to look at the clubs and see if their Id's is inside a bag. like
getAllClubsInBag: publicProcedure
.input(z.object({ bagId: z.array(z.string()) }))
.query(({ ctx, input }) => {
return ctx.prisma.disc.findMany({
where: {
bagId: input.bagId,
},
});
}),
getAllClubsInBag: publicProcedure
.input(z.object({ bagId: z.array(z.string()) }))
.query(({ ctx, input }) => {
return ctx.prisma.disc.findMany({
where: {
bagId: input.bagId,
},
});
}),
But since the bagId is just a string. I can't like map over each bag and use their id against this procedure. Cause in my database, the bagId is null on the discs. And also just a singular string.
5 replies
TTCTheo's Typesafe Cult
Created by fjzon on 4/14/2023 in #questions
Create a User model in Prisma with Clerk on Signup
One of the benefits I find with NextAuth is that it simplifies a lot by adding a User model to Prisma, so that I have each user in my database right at the start. I'm having some difficulties in finding some documentation to implement this with Clerk. I guess that I need to create some kind of mutation right when the user signs up. But in that case I would need the data (atleast userId) right when the user creates their account (I am using Discord Provider). Anyone know of some kind of solution to implement this? Do I perhaps need to create some custom authentication with Clerk?
57 replies
TTCTheo's Typesafe Cult
Created by fjzon on 4/13/2023 in #questions
Add expo-router to create-t3-turbo-clerk
Since the create-t3-turbo is using the expo-router lib, I thought James version (with Clerk) was too. Got pretty confused when I couldn't see the app-folder. Well I can see he's working on it since there's a branch literally called expo-router. Now, does anyone now if there's any guide on how to implement expo-router to the current main code? I know I probably could just read all the changes currently done from James. But I'm too stupid to understand everything and there's a risk something probably would go wrong.
8 replies