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 { 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; }) }; }