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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user