24 lines
679 B
TypeScript
24 lines
679 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;
|
|
})
|
|
};
|
|
}
|