fix: gravity deducted before AI call, causing deduction on failure

- Split checkAndDeductInterview into checkInterview (read-only) and
  deductInterview (deduction only)
- Restructure interview.create(): check gravity -> AI call -> deduct on success
- If AI call fails, gravity is never deducted
- Keep old checkAndDeductInterview for backward compatibility
This commit is contained in:
yuzhiran
2026-06-25 08:36:57 +08:00
parent 2fddd39301
commit 9b1c92464e
2 changed files with 36 additions and 1 deletions
@@ -21,14 +21,19 @@ export class InterviewService {
) {}
async create(userId: string, position: string) {
await this.quotaService.checkAndDeductInterview(userId)
// Step 1: 先检查引力值是否足够(不扣除)
const cost = await this.quotaService.checkInterview(userId)
// Step 2: AI 生成第一个问题
const firstQuestion = await this.aiService.call({
systemPrompt: `你是一位专业的${position}面试官。请针对校招该岗位提出第一个面试问题,要求具体且有针对性。直接输出问题,不要多余内容。`,
userMessage: `请为${position}岗位的校招候选人提出第一个面试问题。`,
temperature: 0.8,
})
// Step 3: AI 调用成功后,扣除引力值并创建面试记录
await this.quotaService.deductInterview(userId, cost)
const interview = await this.interviewModel.create({
userId,
position,