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,25 @@
import { 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 { Book, MutationBookChapterDeleteArgs } from '@generated/types';
import { toBookSchema } from './mappers/bookMapper';
export async function BookChapterDeleteResolver(
_: any,
{ id }: MutationBookChapterDeleteArgs,
{ req, res, identity }: IdentityContext
): Promise<Book> {
ensureIdentity(identity);
const model = await prisma.bookChapter.findUniqueOrThrow({
where: { id },
select: { book: { select: { id: true, authorId: true } } }
});
if (identity.id !== model.book.authorId) throw new Error('Operation is not permitted.');
await prisma.bookChapter.delete({ where: { id } });
await updateBookStats(model.book.id);
const book = await prisma.book.findUniqueOrThrow({ where: { id: model.book.id } });
return toBookSchema(book, { req, res, identity });
}