From 14bc2ccd264bfac639101699496069291b643948 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Thu, 18 Sep 2025 19:59:35 +0200 Subject: [PATCH 1/8] feat: api endpoint to create comment --- src/api/ai-workflow/ai-workflow.controller.ts | 38 +++++++++++++++ src/api/ai-workflow/ai-workflow.service.ts | 46 +++++++++++++++++++ src/dto/aiWorkflow.dto.ts | 12 +++++ 3 files changed, 96 insertions(+) diff --git a/src/api/ai-workflow/ai-workflow.controller.ts b/src/api/ai-workflow/ai-workflow.controller.ts index 57188f5..f8f2972 100644 --- a/src/api/ai-workflow/ai-workflow.controller.ts +++ b/src/api/ai-workflow/ai-workflow.controller.ts @@ -24,6 +24,7 @@ import { UpdateAiWorkflowDto, CreateAiWorkflowRunItemsDto, UpdateAiWorkflowRunDto, + CreateRunItemCommentDto, } from '../../dto/aiWorkflow.dto'; import { Scopes } from 'src/shared/decorators/scopes.decorator'; import { UserRole } from 'src/shared/enums/userRole.enum'; @@ -38,6 +39,43 @@ import { User } from 'src/shared/decorators/user.decorator'; export class AiWorkflowController { constructor(private readonly aiWorkflowService: AiWorkflowService) {} + @Post('/:workflowId/runs/:runId/items/:itemId/comments') + @Roles( + UserRole.Submitter, + UserRole.Copilot, + UserRole.ProjectManager, + UserRole.Admin, + ) + @Scopes(Scope.CreateWorkflowRun) + @ApiOperation({ summary: 'Create a comment for a specific run item' }) + @ApiResponse({ + status: 201, + description: 'Comment created successfully.', + }) + @ApiResponse({ status: 400, description: 'Bad Request.' }) + @ApiResponse({ status: 401, description: 'Unauthorized.' }) + @ApiResponse({ status: 403, description: 'Forbidden.' }) + @ApiResponse({ + status: 404, + description: 'Workflow, Run, or Item not found.', + }) + async createRunItemComment( + @Param('workflowId') workflowId: string, + @Param('runId') runId: string, + @Param('itemId') itemId: string, + @Body(new ValidationPipe({ whitelist: true, transform: true })) + body: CreateRunItemCommentDto, + @User() user: JwtUser, + ) { + return this.aiWorkflowService.createRunItemComment( + workflowId, + runId, + itemId, + body, + user, + ); + } + @Post() @Roles(UserRole.Admin) @Scopes(Scope.CreateWorkflow) diff --git a/src/api/ai-workflow/ai-workflow.service.ts b/src/api/ai-workflow/ai-workflow.service.ts index e75d38a..f279007 100644 --- a/src/api/ai-workflow/ai-workflow.service.ts +++ b/src/api/ai-workflow/ai-workflow.service.ts @@ -10,6 +10,7 @@ import { PrismaService } from '../../shared/modules/global/prisma.service'; import { CreateAiWorkflowDto, CreateAiWorkflowRunDto, + CreateRunItemCommentDto, UpdateAiWorkflowDto, UpdateAiWorkflowRunDto, } from '../../dto/aiWorkflow.dto'; @@ -36,6 +37,51 @@ export class AiWorkflowService { this.logger = LoggerService.forRoot('AiWorkflowService'); } + async createRunItemComment( + workflowId: string, + runId: string, + itemId: string, + body: CreateRunItemCommentDto, + user: JwtUser, + ) { + const workflow = await this.prisma.aiWorkflow.findUnique({ + where: { id: workflowId }, + }); + if (!workflow) { + throw new NotFoundException(`Workflow with id ${workflowId} not found.`); + } + + const run = await this.prisma.aiWorkflowRun.findUnique({ + where: { id: runId }, + }); + if (!run || run.workflowId !== workflowId) { + throw new NotFoundException( + `Run with id ${runId} not found or does not belong to workflow ${workflowId}.`, + ); + } + + const item = await this.prisma.aiWorkflowRunItem.findUnique({ + where: { id: itemId }, + }); + if (!item || item.workflowRunId !== runId) { + throw new NotFoundException( + `Item with id ${itemId} not found or does not belong to run ${runId}.`, + ); + } + + const createdComment = await this.prisma.aiWorkflowRunItemComment.create({ + data: { + workflowRunItemId: itemId, + content: body.content, + parentId: body.parentId ?? null, + userId: user.userId!, + createdAt: new Date(), + }, + }); + + return createdComment; + } + async scorecardExists(scorecardId: string): Promise { const count = await this.prisma.scorecard.count({ where: { id: scorecardId, status: ScorecardStatus.ACTIVE }, diff --git a/src/dto/aiWorkflow.dto.ts b/src/dto/aiWorkflow.dto.ts index b5332b3..dfeabff 100644 --- a/src/dto/aiWorkflow.dto.ts +++ b/src/dto/aiWorkflow.dto.ts @@ -138,3 +138,15 @@ export class CreateAiWorkflowRunItemsDto { @Type(() => CreateAiWorkflowRunItemDto) items: CreateAiWorkflowRunItemDto[]; } + +export class CreateRunItemCommentDto { + @ApiProperty() + @IsString() + @IsNotEmpty() + content: string; + + @ApiProperty({ required: false }) + @IsString() + @IsOptional() + parentId?: string; +} From ec32e69cf3e4a46bf515ab64fd06b83ea459deb0 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Thu, 18 Sep 2025 19:59:44 +0200 Subject: [PATCH 2/8] feat: api endpoint to create comment --- src/api/ai-workflow/ai-workflow.service.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/api/ai-workflow/ai-workflow.service.ts b/src/api/ai-workflow/ai-workflow.service.ts index f279007..f2b6347 100644 --- a/src/api/ai-workflow/ai-workflow.service.ts +++ b/src/api/ai-workflow/ai-workflow.service.ts @@ -75,7 +75,6 @@ export class AiWorkflowService { content: body.content, parentId: body.parentId ?? null, userId: user.userId!, - createdAt: new Date(), }, }); From f86b440852ffddd1986067273ec42bd231ef82d7 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Thu, 18 Sep 2025 22:05:45 +0200 Subject: [PATCH 3/8] feat: api endpoint to create comment --- .circleci/config.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3737228..34e926a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -76,6 +76,7 @@ workflows: - develop - feat/ai-workflows - pm-1782 + - pm-1955 - 'build-prod': context: org-global From 103e3aa6391f73ea231e068821b9d21bbf98fdbe Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Thu, 18 Sep 2025 22:14:31 +0200 Subject: [PATCH 4/8] fix: removed m2m access to adding comment --- src/api/ai-workflow/ai-workflow.controller.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/api/ai-workflow/ai-workflow.controller.ts b/src/api/ai-workflow/ai-workflow.controller.ts index f8f2972..25f99df 100644 --- a/src/api/ai-workflow/ai-workflow.controller.ts +++ b/src/api/ai-workflow/ai-workflow.controller.ts @@ -46,7 +46,6 @@ export class AiWorkflowController { UserRole.ProjectManager, UserRole.Admin, ) - @Scopes(Scope.CreateWorkflowRun) @ApiOperation({ summary: 'Create a comment for a specific run item' }) @ApiResponse({ status: 201, From ea51d14bc353e80c908c84859524dd7e8515234b Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Thu, 18 Sep 2025 22:21:30 +0200 Subject: [PATCH 5/8] removed circle config --- .circleci/config.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 34e926a..3737228 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -76,7 +76,6 @@ workflows: - develop - feat/ai-workflows - pm-1782 - - pm-1955 - 'build-prod': context: org-global From 6c59dc9ada296fc1fa2a420b8f6f27b98969c694 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Thu, 18 Sep 2025 22:22:47 +0200 Subject: [PATCH 6/8] feat: api endpoint to create comment --- src/api/ai-workflow/ai-workflow.controller.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/api/ai-workflow/ai-workflow.controller.ts b/src/api/ai-workflow/ai-workflow.controller.ts index 25f99df..39fb5af 100644 --- a/src/api/ai-workflow/ai-workflow.controller.ts +++ b/src/api/ai-workflow/ai-workflow.controller.ts @@ -45,6 +45,8 @@ export class AiWorkflowController { UserRole.Copilot, UserRole.ProjectManager, UserRole.Admin, + UserRole.Reviewer, + UserRole.User, ) @ApiOperation({ summary: 'Create a comment for a specific run item' }) @ApiResponse({ From ddda8fd5c97cbb230a1a3f27ed3b005209f1d4ce Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Fri, 19 Sep 2025 13:41:05 +0200 Subject: [PATCH 7/8] updated from dev --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index f5abda5..3cb6011 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -75,7 +75,7 @@ workflows: only: - develop - feat/ai-workflows - - pm-1792 + - pm-1955 - 'build-prod': From db2868d8827233642cb8c3d85e39e43977a3e290 Mon Sep 17 00:00:00 2001 From: Hentry Martin Date: Fri, 19 Sep 2025 21:00:17 +0200 Subject: [PATCH 8/8] updated from dev --- src/dto/aiWorkflow.dto.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/dto/aiWorkflow.dto.ts b/src/dto/aiWorkflow.dto.ts index ec3fa9c..4b26dcb 100644 --- a/src/dto/aiWorkflow.dto.ts +++ b/src/dto/aiWorkflow.dto.ts @@ -1,4 +1,9 @@ -import { ApiHideProperty, ApiProperty, OmitType, PartialType } from '@nestjs/swagger'; +import { + ApiHideProperty, + ApiProperty, + OmitType, + PartialType, +} from '@nestjs/swagger'; import { IsString, IsNotEmpty,