added mappers, updated models
This commit is contained in:
parent
6ada519e06
commit
a8375b99c2
11 changed files with 306 additions and 120 deletions
24
app/server/graphql/resolvers/mappers/reviewMapper.ts
Normal file
24
app/server/graphql/resolvers/mappers/reviewMapper.ts
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
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;
|
||||
})
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue