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 {
|
export class AiAnalysisRepository {
|
||||||
constructor(private readonly prisma: PrismaService) {}
|
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) {
|
async createJob(userId: string, jobType: string, sessionId?: string, answerId?: string) {
|
||||||
return this.prisma.aiAnalysisJob.create({
|
return this.prisma.aiJob.create({
|
||||||
data: {
|
data: {
|
||||||
userId,
|
userId,
|
||||||
jobType,
|
jobType,
|
||||||
@ -14,6 +22,12 @@ export class AiAnalysisRepository {
|
|||||||
answerId: answerId ?? null,
|
answerId: answerId ?? null,
|
||||||
status: 'pending',
|
status: 'pending',
|
||||||
queuedAt: new Date(),
|
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) {
|
async updateJobStatus(id: string, status: string, errorMessage?: string) {
|
||||||
const data: Record<string, any> = { status };
|
const data: Record<string, any> = { status };
|
||||||
if (status === 'processing') data.startedAt = new Date();
|
if (status === 'processing') data.startedAt = new Date();
|
||||||
if (status === 'completed' || status === 'failed') data.completedAt = new Date();
|
if (status === 'completed' || status === 'failed') data.finishedAt = new Date();
|
||||||
if (errorMessage) data.errorMessage = errorMessage;
|
if (errorMessage) data.internalErrorMessage = errorMessage;
|
||||||
return this.prisma.aiAnalysisJob.update({ where: { id }, data });
|
|
||||||
|
// ── 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) {
|
async findJobById(id: string) {
|
||||||
return this.prisma.aiAnalysisJob.findUnique({
|
return this.prisma.aiJob.findUnique({
|
||||||
where: { id },
|
where: { id },
|
||||||
include: { results: true },
|
include: { results: true },
|
||||||
});
|
});
|
||||||
|
|||||||
@ -60,8 +60,8 @@ export class AiAnalysisService {
|
|||||||
status: job.status,
|
status: job.status,
|
||||||
queuedAt: job.queuedAt,
|
queuedAt: job.queuedAt,
|
||||||
startedAt: job.startedAt,
|
startedAt: job.startedAt,
|
||||||
completedAt: job.completedAt,
|
completedAt: job.finishedAt,
|
||||||
errorMessage: job.errorMessage,
|
errorMessage: job.internalErrorMessage,
|
||||||
results: job.results,
|
results: job.results,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user