added mappers, updated models
This commit is contained in:
parent
6ada519e06
commit
a8375b99c2
11 changed files with 306 additions and 120 deletions
22
app/server/graphql/resolvers/mappers/bookMapper.ts
Normal file
22
app/server/graphql/resolvers/mappers/bookMapper.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { call } from '@app/common';
|
||||
import { prisma } from '@app/server/prisma/client';
|
||||
import { Book as BookSchema } from '@generated/types';
|
||||
import { Book } from '@prisma/client';
|
||||
|
||||
export async function toBookSchema(model: Book): Promise<BookSchema> {
|
||||
return {
|
||||
id: model.id,
|
||||
workingId: model.workingId,
|
||||
createdAt: model.createdAt.toISOString(),
|
||||
updatedAt: model.updatedAt.toISOString(),
|
||||
wordsTotal: model.wordsTotal,
|
||||
chaptersTotal: await call(async () => {
|
||||
const chaptersCount = await prisma.bookChapter.count({
|
||||
where: {
|
||||
bookId: model.id
|
||||
}
|
||||
});
|
||||
return chaptersCount;
|
||||
})
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue