Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled
前端: - store 改为 votedArtists[] + zustand persist - VoteModal 删除 1/3/5/ALL 选择器,改三态(待投/已投/满额) - 卡片/排行/详情页加 hasVoted 状态 + ✓ 角标 - Hero 右上角 Countdown 替换为 HeroVoteProgress(12 格点亮进度) - /me 改为终身额度叙事(QuotaCard / StatsGrid / MyFanSupport) 后端: - votes 表加 @@unique([userId, artistId])(已 apply 到生产 RDS) - /api/vote 重写:12 票上限 + P2002 ALREADY_VOTED + P2003 NOT_FOUND 兜底 - /api/me 新增 votedArtists[] + voteQuota,移除 dailyQuota - 新增 ERR.ALREADY_VOTED 错误码 测试: - DB 层 5/5 + E2E 18/18 通过(scripts/e2e-vote-flow.sh) - 修复 P2003 FK 违反未识别的 bug 详情见 docs/todo/voting-refactor-完成报告.md 与 voting-refactor-backend-完成报告.md Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
// 删除测试用户 + 其所有 vote / fanSupport / signIn 数据,
|
|
// 并把 artist.voteCount 回滚到投票前的值。
|
|
//
|
|
// 用法: node scripts/cleanup-test-user.mjs <phone>
|
|
import { PrismaClient } from "@prisma/client";
|
|
const prisma = new PrismaClient({ log: ["error"] });
|
|
|
|
const phone = process.argv[2];
|
|
if (!phone) {
|
|
console.error("用法: node scripts/cleanup-test-user.mjs <phone>");
|
|
process.exit(2);
|
|
}
|
|
|
|
const user = await prisma.user.findUnique({
|
|
where: { phone },
|
|
select: { id: true, nickname: true },
|
|
});
|
|
if (!user) {
|
|
console.log(`[skip] 没有找到 phone=${phone} 的用户,无需 cleanup`);
|
|
await prisma.$disconnect();
|
|
process.exit(0);
|
|
}
|
|
|
|
console.log(`[cleanup] 用户 id=${user.id} (${user.nickname}) phone=${phone}`);
|
|
|
|
// 1. 把该用户的投票回滚到 artist.voteCount
|
|
const votes = await prisma.vote.findMany({
|
|
where: { userId: user.id },
|
|
select: { artistId: true, count: true },
|
|
});
|
|
console.log(` 待回滚 ${votes.length} 条投票`);
|
|
|
|
await prisma.$transaction(async (tx) => {
|
|
// 1. 减回 artist.voteCount
|
|
for (const v of votes) {
|
|
await tx.artist.update({
|
|
where: { id: v.artistId },
|
|
data: { voteCount: { decrement: v.count } },
|
|
});
|
|
}
|
|
// 2. 删除 Vote / FanSupport / SignIn(都有 onDelete: Cascade,删 user 就够,但显式更清晰)
|
|
// 3. 删除 user 本身 —— cascade 会清掉关联表
|
|
await tx.user.delete({ where: { id: user.id } });
|
|
});
|
|
|
|
console.log("[cleanup] 完成");
|
|
await prisma.$disconnect();
|