26 lines
768 B
TypeScript
26 lines
768 B
TypeScript
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 } })
|
|
};
|
|
}
|