#How to make includes dry?
5 messages · Page 1 of 1 (latest)
look here:
export default class UserRepository {
static async findById(id: string): Promise<User> {
return await database.user.findUnique({
where: { id },
include: {
blogs: {
orderBy: { slug: 'asc' }
},
posts: {
orderBy: { publishedAt: 'desc' }
},
comments: {
orderBy: { createdAt: 'asc' }
}
}
})
}
static async findByBlogId(blogId: string) {}
static async findByPostId(postId: string) {}
static async findByCommentId(commentId: string) {}
}
Heyho!
I've got it.
const include: UserInclude = {
blogs: {
orderBy: { slug: 'asc' }
},
posts: {
orderBy: { publishedAt: 'desc' }
},
comments: {
orderBy: { createdAt: 'asc' }
}
}