added mappers, updated models

This commit is contained in:
lnn0q 2025-05-17 17:16:26 +03:00
parent 6ada519e06
commit a8375b99c2
11 changed files with 306 additions and 120 deletions

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