ln/app/server/graphql/resolvers/mappers/reviewMapper.ts
2025-05-17 17:16:26 +03:00

24 lines
678 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,
//todo: ratings implementation
ratingTotal: await call(async () => {
return 0;
})
};
}