ln/app/server/graphql/resolvers/mappers/reviewMapper.ts
2025-06-01 17:54:57 +03:00

26 lines
771 B
TypeScript

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<ReviewSchema> {
return {
id: model.id,
author: await call(async () => {
const userModel = await prisma.user.findUniqueOrThrow({
where: {
id: model.userId
}
});
return toUserSchema(userModel);
}),
text: model.text,
createdAt: model.createdAt.toISOString(),
updatedAt: model.updatedAt.toISOString(),
// todo: ratings implementation
ratingTotal: await call(async () => {
return 0;
})
};
}