added chapter view, fixes, added ratings, added chapter updates/deletions
This commit is contained in:
parent
029b7e9353
commit
4801cf3a13
34 changed files with 1345 additions and 191 deletions
26
app/server/service/book.ts
Normal file
26
app/server/service/book.ts
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
import { prisma } from '@app/server/prisma/client';
|
||||
|
||||
export async function updateBookStats(id: string) {
|
||||
const bookWordsTotal = await prisma.bookChapter.aggregate({
|
||||
where: {
|
||||
bookId: id
|
||||
},
|
||||
_sum: {
|
||||
wordsTotal: true
|
||||
}
|
||||
});
|
||||
|
||||
const chaptersTotal = await prisma.bookChapter.count({
|
||||
where: {
|
||||
bookId: id
|
||||
}
|
||||
});
|
||||
|
||||
return prisma.book.update({
|
||||
where: { id },
|
||||
data: {
|
||||
wordsTotal: bookWordsTotal._sum.wordsTotal != null ? bookWordsTotal._sum.wordsTotal : 0,
|
||||
chaptersTotal
|
||||
}
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue