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