import { Review } from '@prisma/client'; import { Review as ReviewSchema } from '@generated/types'; import { toUserSchema } from './userMapper'; import { call } from '@app/common'; import { prisma } from '@app/server/prisma/client'; export async function toReviewSchema(model: Review): Promise { return { id: model.id, author: await call(async () => { const userModel = await prisma.user.findUniqueOrThrow({ where: { id: model.userId } }); return toUserSchema(userModel); }), text: model.text, // todo: ratings implementation ratingTotal: await call(async () => { return 0; }) }; }