Fervore
Fervore
Explore posts from servers
PPrisma
Created by Fervore on 7/22/2024 in #help-and-questions
Nested relation query help
hello @moosthuizen, thanks for reaching out, here are the models in question from the schema.prisma
model Member {
id String @id() @default(cuid())
name String
email String?
phone Int?
sex String
DNI String
memberships Membership[]
payments Payment[]
orgId String
organization Organization @relation(fields: [orgId], references: [id])
}

model Membership {
id String @id() @default(cuid())
period Int
cost Int
name String
members Member[]
payments Payment[]
authorId String
createdBy User @relation(fields: [authorId], references: [id])
orgId String
organization Organization @relation(fields: [orgId], references: [id])
}

model Payment {
id String @id() @default(cuid())
startDate DateTime @default(now())
endDate DateTime
membership Membership @relation(fields: [membershipId], references: [id])
membershipId String
amount Int @default(0)
member Member @relation(fields: [memberId], references: [id])
memberId String
createdBy User @relation(fields: [authorId], references: [id])
authorId String
createdAt DateTime @default(now())
}

model Organization {
id String @id() @default(cuid())
name String
createdAt DateTime @default(now())
slug String
members Member[]
users User[] @relation("organization")
ownerId String @unique()
owner User @relation("owns", fields: [ownerId], references: [id])
memberships Membership[]
}
model Member {
id String @id() @default(cuid())
name String
email String?
phone Int?
sex String
DNI String
memberships Membership[]
payments Payment[]
orgId String
organization Organization @relation(fields: [orgId], references: [id])
}

model Membership {
id String @id() @default(cuid())
period Int
cost Int
name String
members Member[]
payments Payment[]
authorId String
createdBy User @relation(fields: [authorId], references: [id])
orgId String
organization Organization @relation(fields: [orgId], references: [id])
}

model Payment {
id String @id() @default(cuid())
startDate DateTime @default(now())
endDate DateTime
membership Membership @relation(fields: [membershipId], references: [id])
membershipId String
amount Int @default(0)
member Member @relation(fields: [memberId], references: [id])
memberId String
createdBy User @relation(fields: [authorId], references: [id])
authorId String
createdAt DateTime @default(now())
}

model Organization {
id String @id() @default(cuid())
name String
createdAt DateTime @default(now())
slug String
members Member[]
users User[] @relation("organization")
ownerId String @unique()
owner User @relation("owns", fields: [ownerId], references: [id])
memberships Membership[]
}
6 replies
TTCTheo's Typesafe Cult
Created by Fervore on 7/24/2023 in #questions
How do I fetch from server side with useMutation?
nice now it works, thanks a lot for the help. You're a hero.
19 replies
TTCTheo's Typesafe Cult
Created by Fervore on 7/24/2023 in #questions
How do I fetch from server side with useMutation?
I get the data but it's undefined and it shouldn't be
19 replies
TTCTheo's Typesafe Cult
Created by Fervore on 7/24/2023 in #questions
How do I fetch from server side with useMutation?
I'm guessing this is it? but how do I get the data from the page itself?
export const getServerSideProps: GetServerSideProps = async (context) => {
const session = await getServerSession(context.req, context.res, authOptions);
const helpers = createServerSideHelpers({
router: appRouter,
ctx: {session, prisma},
transformer: superjson,
});
const sub = await helpers.subscription.getUserPendingSubscriptions.prefetch()
const history = await helpers.changesHistory.getCurrentUserHistoryChanges.prefetch();

return {
props: {
...(await serverSideTranslations(context.locale)),
trpcState: helpers.dehydrate(),
},
};
};

export default function Dashboard(props: InferGetServerSidePropsType<typeof getServerSideProps>,) {
const { t } = useTranslation("common");
export const getServerSideProps: GetServerSideProps = async (context) => {
const session = await getServerSession(context.req, context.res, authOptions);
const helpers = createServerSideHelpers({
router: appRouter,
ctx: {session, prisma},
transformer: superjson,
});
const sub = await helpers.subscription.getUserPendingSubscriptions.prefetch()
const history = await helpers.changesHistory.getCurrentUserHistoryChanges.prefetch();

return {
props: {
...(await serverSideTranslations(context.locale)),
trpcState: helpers.dehydrate(),
},
};
};

export default function Dashboard(props: InferGetServerSidePropsType<typeof getServerSideProps>,) {
const { t } = useTranslation("common");
19 replies
TTCTheo's Typesafe Cult
Created by Fervore on 7/24/2023 in #questions
How do I fetch from server side with useMutation?
so there's no way to do it without changing them to queries?
19 replies
TTCTheo's Typesafe Cult
Created by Fervore on 7/24/2023 in #questions
How do I fetch from server side with useMutation?
I previously had them as queries but they would refresh my page everytime the window focused and I couldn't figure out how to remove that also so that's why they were made into mutations
19 replies
TTCTheo's Typesafe Cult
Created by Fervore on 7/24/2023 in #questions
How do I fetch from server side with useMutation?
Ok so I did the create server side helpers object, it asked me to send context whith session and prisma and I did(I think so) but it still doesn't work, it's not recognizing the methods, what am I missing ?
import { useSession } from "next-auth/react";
import { prisma } from "sellit/server/db";
import { SessionContext, getSession } from "next-auth/react";

export const getStaticProps: GetStaticProps = async ({ locale = "en"}) => {
const session = await getSession();
const helpers = createServerSideHelpers({
router: appRouter,
ctx: {session, prisma},
});
//Property 'getUserPendingSubscriptions' does not exist on type //'DecoratedProcedureSSGRecord<CreateRouterInner<RootConfig<...
const sub = await helpers.subscription.getUserPendingSubscriptions.prefetch({});
//Property 'getCurrentUserHistoryChanges' does not exist on type //'DecoratedProcedureSSGRecord<CreateRouterInner<RootConfig<...
const history = await helpers.changesHistory.getCurrentUserHistoryChanges.prefetch({});


return {
props: {
...(await serverSideTranslations(locale)),
sub,
history
},
};
};
import { useSession } from "next-auth/react";
import { prisma } from "sellit/server/db";
import { SessionContext, getSession } from "next-auth/react";

export const getStaticProps: GetStaticProps = async ({ locale = "en"}) => {
const session = await getSession();
const helpers = createServerSideHelpers({
router: appRouter,
ctx: {session, prisma},
});
//Property 'getUserPendingSubscriptions' does not exist on type //'DecoratedProcedureSSGRecord<CreateRouterInner<RootConfig<...
const sub = await helpers.subscription.getUserPendingSubscriptions.prefetch({});
//Property 'getCurrentUserHistoryChanges' does not exist on type //'DecoratedProcedureSSGRecord<CreateRouterInner<RootConfig<...
const history = await helpers.changesHistory.getCurrentUserHistoryChanges.prefetch({});


return {
props: {
...(await serverSideTranslations(locale)),
sub,
history
},
};
};
19 replies
TTCTheo's Typesafe Cult
Created by Fervore on 7/24/2023 in #questions
How do I fetch from server side with useMutation?
can you point specifically what component/library/file should I be importing in order to re-use the mutations that I made on the api or am I forced to import prisma and re-do the queries inside getstaticprops?
19 replies
TTCTheo's Typesafe Cult
Created by Fervore on 4/28/2023 in #questions
Type Promise not asignable to type Awaitable
I get it now, thanks!
7 replies
TTCTheo's Typesafe Cult
Created by Fervore on 4/28/2023 in #questions
Type Promise not asignable to type Awaitable
7 replies
TTCTheo's Typesafe Cult
Created by Fervore on 4/28/2023 in #questions
Type Promise not asignable to type Awaitable
Sure, this is not really an error, the function works just fine but vscode is screaming at me. The db is in mysql, this query just looks for the user using the email and stores it in the next-auth session which uses jwt strategy and a credentials provider. logging the user returns the user correctly and if it doesn't find it, it ends up beign null but for some reason whenever I try to write a return user, it gives me that vscode error. As far as I know prisma.findUnique returns a js object after the promise resolves or null if it doesn't find it. It stops screaming at me if I return a hardcoded object. My guess is that maybe authorize expects an Awaitable object instead of just a promise? I wouldn't know how to debug it either since ts is pretty new for me and I'm a bit lost. Also the project is built with t3 app and it's like the first thing that I'm doing on it so there's like nothing else in the app.
7 replies
TTCTheo's Typesafe Cult
Created by Fervore on 1/18/2023 in #questions
I can't figure out how to make an authentication middleware for my API please help
I think that'll do it tnak you very much
6 replies