fix-book-status.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. const { PrismaClient } = require('@prisma/client');
  2. const prisma = new PrismaClient();
  3. async function fixBookStatus() {
  4. try {
  5. // 更新bookId=1的所有level=1的章,将status从pending改为completed
  6. const result = await prisma.bookChapter.updateMany({
  7. where: {
  8. bookId: 1,
  9. level: 1,
  10. status: 'pending'
  11. },
  12. data: {
  13. status: 'completed'
  14. }
  15. });
  16. console.log(`✅ 已修复 ${result.count} 个章的状态: pending → completed`);
  17. // 验证结果
  18. const book = await prisma.book.findUnique({
  19. where: { id: 1 },
  20. include: {
  21. chapters: true
  22. }
  23. });
  24. const level1Chapters = book.chapters.filter(c => c.level === 1);
  25. const statusCount = {
  26. pending: level1Chapters.filter(c => c.status === 'pending').length,
  27. completed: level1Chapters.filter(c => c.status === 'completed').length,
  28. failed: level1Chapters.filter(c => c.status === 'failed').length,
  29. };
  30. console.log('\n📊 验证结果:');
  31. console.log(` 章总数: ${level1Chapters.length}`);
  32. console.log(` pending: ${statusCount.pending}`);
  33. console.log(` completed: ${statusCount.completed}`);
  34. console.log(` failed: ${statusCount.failed}`);
  35. } catch (error) {
  36. console.error('错误:', error);
  37. } finally {
  38. await prisma.$disconnect();
  39. }
  40. }
  41. fixBookStatus();