added mappers, updated models
This commit is contained in:
parent
6ada519e06
commit
a8375b99c2
11 changed files with 306 additions and 120 deletions
23
app/server/graphql/resolvers/mappers/bookChapterMapper.ts
Normal file
23
app/server/graphql/resolvers/mappers/bookChapterMapper.ts
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
import { call } from '@app/common';
|
||||
import { prisma } from '@app/server/prisma/client';
|
||||
import { BookChapter as BookChapterSchema } from '@generated/types';
|
||||
import { BookChapter } from '@prisma/client';
|
||||
|
||||
export async function toBookChapterMapping(model: BookChapter): Promise<BookChapterSchema> {
|
||||
return {
|
||||
id: model.id,
|
||||
title: model.title,
|
||||
createdAt: model.createdAt.toISOString(),
|
||||
updatedAt: model.createdAt.toISOString(),
|
||||
foreword: model.foreword,
|
||||
footnote: model.footnote,
|
||||
reviewsTotal: await call(async () => {
|
||||
const reviewsCount = await prisma.review.count({
|
||||
where: {
|
||||
bookChapterId: model.id
|
||||
}
|
||||
});
|
||||
return reviewsCount;
|
||||
})
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue