P
Prisma7mo ago
Florian

Prisma.validator with arguments

Is this the correct way to use Prisma validator (to reuse parts of a query) if the query depends on dynamic data?
export function getPostDataInclude(loggedInUserId: string | undefined) {
return Prisma.validator<Prisma.PostInclude>()({
user: {
select: {
username: true,
displayName: true,
avatarUrl: true,
pinnedPostId: true,
},
},
likes: {
where: {
userId: loggedInUserId,
},
select: {
userId: true,
},
},
_count: {
select: {
likes: true,
},
},
});
}

export type PostData = Prisma.PostGetPayload<{
include: ReturnType<typeof getPostDataInclude>;
}>;
export function getPostDataInclude(loggedInUserId: string | undefined) {
return Prisma.validator<Prisma.PostInclude>()({
user: {
select: {
username: true,
displayName: true,
avatarUrl: true,
pinnedPostId: true,
},
},
likes: {
where: {
userId: loggedInUserId,
},
select: {
userId: true,
},
},
_count: {
select: {
likes: true,
},
},
});
}

export type PostData = Prisma.PostGetPayload<{
include: ReturnType<typeof getPostDataInclude>;
}>;
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server