added chapter view, fixes, added ratings, added chapter updates/deletions

This commit is contained in:
lnn0q 2025-06-01 00:37:26 +03:00
parent 029b7e9353
commit 4801cf3a13
34 changed files with 1345 additions and 191 deletions

View file

@ -0,0 +1,34 @@
import { countWords, ensureIdentity } from '@app/server/helpers';
import { IdentityContext } from '@app/server/identity';
import { prisma } from '@app/server/prisma/client';
import { updateBookStats } from '@app/server/service/book';
import { BookChapter, MutationBookChapterUpdateArgs } from '@generated/types';
import { toBookChapterSchema } from './mappers/bookChapterMapper';
export async function BookChapterUpdateResolver(
_: any,
{ input }: MutationBookChapterUpdateArgs,
{ req, res, identity }: IdentityContext
): Promise<BookChapter> {
ensureIdentity(identity);
if (input.title.length > 60) throw new Error('Title is too long.');
if (input.foreword != null && input.foreword.length > 500)
throw new Error('Foreword is too long.');
if (input.footnote != null && input.footnote.length > 500)
throw new Error('Footnote is too long.');
const model = await prisma.bookChapter.update({
where: { id: input.id },
data: {
title: input.title,
foreword: input.foreword,
footnote: input.footnote,
content: input.content,
wordsTotal: countWords(input.content)
}
});
await updateBookStats(model.bookId);
return toBookChapterSchema(model, { req, res, identity });
}