feat(challenges): add vip user restrictions for challenge creation

限制非会员用户只能创建一个未归档的自定义挑战,添加用户VIP状态检查和挑战数量限制逻辑
This commit is contained in:
richarjiang
2025-11-27 08:33:46 +08:00
parent 5d64a99ce5
commit 7a05097226

View File

@@ -856,6 +856,29 @@ export class ChallengesService {
throw new BadRequestException('无效的时间戳');
}
// 获取用户信息,检查会员状态
const user = await User.findByPk(userId);
if (!user) {
throw new NotFoundException('用户不存在');
}
// 检查非会员用户已创建的未归档挑战数量
if (!user.isVip) {
const existingChallengeCount = await this.challengeModel.count({
where: {
creatorId: userId,
source: ChallengeSource.CUSTOM,
challengeState: {
[Op.ne]: ChallengeState.ARCHIVED, // 不包含已归档的挑战
},
},
});
if (existingChallengeCount >= 1) {
throw new BadRequestException('非会员用户只能创建一个挑战,您可以先归档现有挑战或升级会员');
}
}
// 检查创建频率限制(每天最多创建 5 个)
const recentCount = await this.challengeModel.count({
where: {
@@ -908,6 +931,8 @@ export class ChallengesService {
userId,
challengeId: challenge.id,
shareCode,
isVip: user.isVip,
existingChallengeCount: user.isVip ? null : 1,
});
return this.buildCustomChallengeResponse(challenge, userId);