ln/app/server/graphql/resolvers/mappers/bookMapper.ts
2025-05-17 17:16:26 +03:00

22 lines
652 B
TypeScript

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