Fervore
Fervore
Explore posts from servers
PPrisma
Created by Fervore on 7/22/2024 in #help-and-questions
Nested relation query help
Hello, I was trying to query users, then I added the implementation to show payments but now I realize it was bringing payments of all users from the membership instead of bringing all payments of that specific user for each specific membership. Is there a way to do this query in the same object or is there a way to reference the current user for each index of the array?
prisma.user.findMany({
orderBy: {
id: 'desc',
},
include: {
memberships: {
include: {
payments: {
take: 1,
orderBy: {
endDate: 'asc'
}
}
}
}
}
})
prisma.user.findMany({
orderBy: {
id: 'desc',
},
include: {
memberships: {
include: {
payments: {
take: 1,
orderBy: {
endDate: 'asc'
}
}
}
}
}
})
Example of what It would be ideal but ofc it doesn't work
prisma.user.findMany({
orderBy: {
id: 'desc',
},
include: {
memberships: {
include: {
payments: {
where: {
memberId: "current_member_id??"
},
take: 1,
orderBy: {
endDate: 'asc'
}
}
}
}
}
})
prisma.user.findMany({
orderBy: {
id: 'desc',
},
include: {
memberships: {
include: {
payments: {
where: {
memberId: "current_member_id??"
},
take: 1,
orderBy: {
endDate: 'asc'
}
}
}
}
}
})
6 replies
TTCTheo's Typesafe Cult
Created by Fervore on 7/24/2023 in #questions
How do I fetch from server side with useMutation?
Hello, I'm trying to do a server side fetch from the mutations that I made in the backend of my t3 app but I'm struggling to understand some things can someone help me please? I'm trying to pass the data from both the queries as props. What would be the most optimal approach to this? This is my code
export const getStaticProps: GetStaticProps = async ({ locale = "en" }) => {

const sub = api.subscription.getUserPendingSubscriptions.useMutation().data;
const history = api.changesHistory.getCurrentUserHistoryChanges.useMutation().data;

return {
props: {
...(await serverSideTranslations(locale)),
sub,
history
},
};
};

export default function Dashboard({ sub, history}) {
...
export const getStaticProps: GetStaticProps = async ({ locale = "en" }) => {

const sub = api.subscription.getUserPendingSubscriptions.useMutation().data;
const history = api.changesHistory.getCurrentUserHistoryChanges.useMutation().data;

return {
props: {
...(await serverSideTranslations(locale)),
sub,
history
},
};
};

export default function Dashboard({ sub, history}) {
...
19 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 1/18/2023 in #questions
I can't figure out how to make an authentication middleware for my API please help
I'm using credentials provider with jwt from nextauth and then I have a middleware.ts in the root folder with just this content
export { default } from "next-auth/middleware"

export const config = {
matcher: ['/api/user/getuser'],
};
export { default } from "next-auth/middleware"

export const config = {
matcher: ['/api/user/getuser'],
};
which works if I pass static pages on the matcher but It doesn't work for the api. I've also tried to make a wrapper middleware returning an async function inside sort of but I get something like resolver is not defined so how can I make just a simple middleware that checks if the user is logged in on the backend? I've tried lots of tutorials and read the docs too and I can't make it work. 😦 Can I get some help or at least get pointed in the right direction?
6 replies