check-status.js 986 B

12345678910111213141516171819202122232425262728293031323334
  1. const { PrismaClient } = require('@prisma/client');
  2. const prisma = new PrismaClient();
  3. async function checkStatus() {
  4. const book = await prisma.book.findUnique({
  5. where: { id: 1 },
  6. include: { chapters: true }
  7. });
  8. if (!book) {
  9. console.log('书籍不存在');
  10. return;
  11. }
  12. const level1 = book.chapters.filter(c => c.level === 1).length;
  13. const level2 = book.chapters.filter(c => c.level === 2).length;
  14. const level3 = book.chapters.filter(c => c.level === 3).length;
  15. console.log(`状态: ${book.status}`);
  16. console.log(`进度: ${book.progress}%`);
  17. console.log(`章: ${level1}, 节: ${level2}, 小节: ${level3}`);
  18. console.log(`总计: ${book.chapters.length} 条记录`);
  19. if (level1 > 0) {
  20. console.log('\n章节列表:');
  21. book.chapters.filter(c => c.level === 1).forEach(c => {
  22. console.log(` - 第${c.number}章: ${c.title} [${c.status}]`);
  23. });
  24. }
  25. await prisma.$disconnect();
  26. }
  27. checkStatus().catch(console.error);