implemented ratings, fixes
This commit is contained in:
parent
4801cf3a13
commit
d1da980501
31 changed files with 775 additions and 236 deletions
|
|
@ -13,12 +13,29 @@ export async function BookChapterDeleteResolver(
|
|||
ensureIdentity(identity);
|
||||
const model = await prisma.bookChapter.findUniqueOrThrow({
|
||||
where: { id },
|
||||
select: { book: { select: { id: true, authorId: true } } }
|
||||
select: {
|
||||
sequenceNumber: true,
|
||||
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 prisma.bookChapter.updateMany({
|
||||
where: {
|
||||
bookId: model.book.id,
|
||||
sequenceNumber: {
|
||||
gt: model.sequenceNumber
|
||||
}
|
||||
},
|
||||
data: {
|
||||
sequenceNumber: {
|
||||
decrement: 1
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
await updateBookStats(model.book.id);
|
||||
const book = await prisma.book.findUniqueOrThrow({ where: { id: model.book.id } });
|
||||
return toBookSchema(book, { req, res, identity });
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue