implemented ratings, fixes
This commit is contained in:
parent
4801cf3a13
commit
d1da980501
31 changed files with 775 additions and 236 deletions
|
|
@ -12,13 +12,26 @@ export async function BookChapterUpdateResolver(
|
|||
): Promise<BookChapter> {
|
||||
ensureIdentity(identity);
|
||||
|
||||
const model = await prisma.bookChapter.findUniqueOrThrow({
|
||||
where: { id: input.id },
|
||||
select: {
|
||||
book: {
|
||||
select: {
|
||||
authorId: true
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if (identity.id !== model.book.authorId) throw new Error('Operation is not permitted.');
|
||||
|
||||
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({
|
||||
const modelUpdated = await prisma.bookChapter.update({
|
||||
where: { id: input.id },
|
||||
data: {
|
||||
title: input.title,
|
||||
|
|
@ -29,6 +42,6 @@ export async function BookChapterUpdateResolver(
|
|||
}
|
||||
});
|
||||
|
||||
await updateBookStats(model.bookId);
|
||||
return toBookChapterSchema(model, { req, res, identity });
|
||||
await updateBookStats(modelUpdated.bookId);
|
||||
return toBookChapterSchema(modelUpdated, { req, res, identity });
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue