implemented ratings, fixes

This commit is contained in:
lnn0q 2025-06-01 17:54:57 +03:00
parent 4801cf3a13
commit d1da980501
31 changed files with 775 additions and 236 deletions

View file

@ -0,0 +1,26 @@
import { IdentityContext } from '@app/server/identity';
import { prisma } from '@app/server/prisma/client';
import { QueryReviewManyArgs, ReviewManyOutput } from '@generated/types';
import { toReviewSchema } from './mappers/reviewMapper';
export async function ReviewManyResolver(
_: any,
{ input }: QueryReviewManyArgs,
{ req, res, identity }: IdentityContext
): Promise<ReviewManyOutput> {
const { bookId, filter } = input;
const items = await prisma.review.findMany({
where: { bookId },
skip: filter.offset ?? 0,
take: filter.size ?? 10,
orderBy: {
createdAt: 'desc'
}
});
return {
items: await Promise.all(items.map(value => toReviewSchema(value))),
total: await prisma.review.count({ where: { bookId } })
};
}