fix(M-AI-02-04): adapt source to renamed Prisma fields
- completedAt → finishedAt, errorMessage → internalErrorMessage - API JSON keys preserved for backward compat Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
0f1f2e5123
commit
f4259e70a0
@ -5,8 +5,16 @@ import { PrismaService } from '../../infrastructure/database/prisma.service';
|
||||
export class AiAnalysisRepository {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
// ── M-AI-02-10: 旧状态 → 新 lifecycleStatus 映射 ──
|
||||
private static readonly STATUS_TO_LIFECYCLE: Record<string, string> = {
|
||||
pending: 'pending',
|
||||
processing: 'running',
|
||||
completed: 'succeeded',
|
||||
failed: 'failed',
|
||||
};
|
||||
|
||||
async createJob(userId: string, jobType: string, sessionId?: string, answerId?: string) {
|
||||
return this.prisma.aiAnalysisJob.create({
|
||||
return this.prisma.aiJob.create({
|
||||
data: {
|
||||
userId,
|
||||
jobType,
|
||||
@ -14,6 +22,12 @@ export class AiAnalysisRepository {
|
||||
answerId: answerId ?? null,
|
||||
status: 'pending',
|
||||
queuedAt: new Date(),
|
||||
// ── M-AI-02-10 Shadow Write ──
|
||||
lifecycleStatus: 'pending',
|
||||
triggerType: 'api',
|
||||
queueName: 'ai-interactive',
|
||||
inputSchemaVersion: 'legacy-v1',
|
||||
attemptCount: 0,
|
||||
},
|
||||
});
|
||||
}
|
||||
@ -21,13 +35,18 @@ export class AiAnalysisRepository {
|
||||
async updateJobStatus(id: string, status: string, errorMessage?: string) {
|
||||
const data: Record<string, any> = { status };
|
||||
if (status === 'processing') data.startedAt = new Date();
|
||||
if (status === 'completed' || status === 'failed') data.completedAt = new Date();
|
||||
if (errorMessage) data.errorMessage = errorMessage;
|
||||
return this.prisma.aiAnalysisJob.update({ where: { id }, data });
|
||||
if (status === 'completed' || status === 'failed') data.finishedAt = new Date();
|
||||
if (errorMessage) data.internalErrorMessage = errorMessage;
|
||||
|
||||
// ── M-AI-02-10 Shadow Write:映射旧 status 到新 lifecycleStatus ──
|
||||
const lifecycleStatus = AiAnalysisRepository.STATUS_TO_LIFECYCLE[status];
|
||||
if (lifecycleStatus) data.lifecycleStatus = lifecycleStatus;
|
||||
|
||||
return this.prisma.aiJob.update({ where: { id }, data });
|
||||
}
|
||||
|
||||
async findJobById(id: string) {
|
||||
return this.prisma.aiAnalysisJob.findUnique({
|
||||
return this.prisma.aiJob.findUnique({
|
||||
where: { id },
|
||||
include: { results: true },
|
||||
});
|
||||
|
||||
@ -60,8 +60,8 @@ export class AiAnalysisService {
|
||||
status: job.status,
|
||||
queuedAt: job.queuedAt,
|
||||
startedAt: job.startedAt,
|
||||
completedAt: job.completedAt,
|
||||
errorMessage: job.errorMessage,
|
||||
completedAt: job.finishedAt,
|
||||
errorMessage: job.internalErrorMessage,
|
||||
results: job.results,
|
||||
};
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user