Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ workflows:
only:
- develop
- feat/ai-workflows
- pm-1957
- pm-1955_2


- 'build-prod':
Expand Down
73 changes: 63 additions & 10 deletions src/api/ai-workflow/ai-workflow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,27 @@ export class AiWorkflowService {
throw new BadRequestException(`User id is not available`);
}

const createdComment = await this.prisma.aiWorkflowRunItemComment.create({
data: {
workflowRunItemId: itemId,
content: body.content,
parentId: body.parentId ?? null,
userId: user.userId.toString(),
},
});

return createdComment;
try {
const createdComment = await this.prisma.aiWorkflowRunItemComment.create({
data: {
workflowRunItemId: itemId,
content: body.content,
parentId: body.parentId ?? null,
userId: user.userId.toString(),
},
});
return createdComment;
} catch (e) {
if (e.code === 'P2003') {
if (
e.meta.field_name === 'aiWorkflowRunItemComment_parentId_fkey (index)'
) {
throw new BadRequestException(
`Invalid parent id provided! Parent comment with id ${body.parentId} does not exist!`,
);
}
}
}
}

async scorecardExists(scorecardId: string): Promise<boolean> {
Expand Down Expand Up @@ -370,6 +381,48 @@ export class AiWorkflowService {

async createWorkflowRun(workflowId: string, runData: CreateAiWorkflowRunDto) {
try {
const submission = runData.submissionId
? await this.prisma.submission.findUnique({
where: { id: runData.submissionId },
})
: null;
const challengeId = submission?.challengeId;

if (!challengeId) {
this.logger.error(
`Challenge ID not found for submission ${runData.submissionId}`,
);
throw new InternalServerErrorException(
`Challenge ID not found for submission ${runData.submissionId}`,
);
}

const challenge: ChallengeData =
await this.challengeApiService.getChallengeDetail(challengeId);

if (!challenge) {
throw new InternalServerErrorException(
`Challenge with id ${challengeId} was not found!`,
);
}

const aiWorkflowAllowedPhases = [
'Submission',
'Review',
'Iterative Review',
];
const isNotInSubmissionOrReviewPhases = challenge.phases
?.filter((item) => item.isOpen)
.some((item) => aiWorkflowAllowedPhases.includes(item.name));
if (
challenge.status !== ChallengeStatus.COMPLETED &&
isNotInSubmissionOrReviewPhases
) {
throw new InternalServerErrorException(
`Challenge is either not completed or its not in one of these phases ${aiWorkflowAllowedPhases.join(',')}`,
);
}

return await this.prisma.aiWorkflowRun.create({
data: {
...runData,
Expand Down