Skip to content

Conversation

hentrymartin
Copy link
Collaborator

What's in this PR?

  • Create AI workflow api implementation

Ticket link - https://topcoder.atlassian.net/browse/PM-1793

@@ -23,7 +23,7 @@ export class GetHealthCheckResponseDto {
}

@ApiTags('Healthcheck')
@Controller('/')
@Controller('/reviews')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from @Controller('/') to @Controller('/reviews') seems to alter the endpoint path for the health check controller. Ensure that this change aligns with the intended functionality of the AI workflow API implementation, as it might affect existing routes and integrations.

@@ -40,7 +40,7 @@ import { JwtUser } from 'src/shared/modules/global/jwt.service';

@ApiTags('ReviewSummations')
@ApiBearerAuth()
@Controller('/api/reviewSummations')
@Controller('/reviewSummations')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change in the route path from /api/reviewSummations to /reviewSummations might affect existing API consumers. Ensure that this change is intentional and that all dependent services or clients are updated accordingly.

@@ -52,7 +52,7 @@ import { JwtUser } from 'src/shared/modules/global/jwt.service';

@ApiTags('Submissions')
@ApiBearerAuth()
@Controller('/api/submissions')
@Controller('/submissions')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change from /api/submissions to /submissions in the @Controller decorator modifies the base route for the SubmissionController. Ensure that this change is intentional and that all relevant parts of the application are updated to reflect this new route, as it may affect API endpoint accessibility.

@@ -66,25 +66,50 @@ export class SubmissionController {
UserRole.Copilot,
UserRole.Submitter,
UserRole.Reviewer,
UserRole.User,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding UserRole.User to the list of roles might need a review to ensure that this role should indeed have the permissions associated with this method. Verify if this role should have access to create submissions.

this.logger.log(
`Creating submission with request boy: ${JSON.stringify(body)}`,
console.log(
`Creating submission with request body: ${JSON.stringify(body)}`,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using console.log for logging is not recommended in production code. Consider using a proper logging library or framework that is already integrated into your application, such as this.logger.log, which was previously used.

@@ -151,6 +176,7 @@ export class SubmissionController {
UserRole.Submitter,
UserRole.Reviewer,
UserRole.Talent,
UserRole.User,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding UserRole.User to the list of roles might require updating the authorization logic to ensure that users with this role have the correct permissions. Please verify that this change aligns with the intended access control policies.

@@ -185,6 +211,7 @@ export class SubmissionController {
UserRole.Admin,
UserRole.Submitter,
UserRole.Reviewer,
UserRole.User,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding UserRole.User to the list of roles might unintentionally broaden access. Please ensure that this role should indeed have access to this functionality, as it could introduce security concerns if not intended.

@@ -20,6 +20,7 @@ export class SubmissionService {
constructor(private readonly prisma: PrismaService) {}

async createSubmission(authUser: JwtUser, body: SubmissionRequestDto) {
console.log(`BODY: ${JSON.stringify(body)}`);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using console.log for logging is not recommended in production code. Consider using a proper logging library to handle logging with different levels and outputs.


@ApiProperty({ required: false })
@IsString()
@IsNotEmpty()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

The @IsNotEmpty() decorator should not be used with optional properties like updatedBy. Consider removing @IsNotEmpty() to accurately reflect that this field can be empty or undefined.

@@ -50,8 +50,8 @@ export class KafkaConsumerService
}

async onApplicationBootstrap() {
await this.subscribeToTopics();
await this.startConsumer();
// await this.subscribeToTopics();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calls to subscribeToTopics() and startConsumer() have been commented out. If this is intentional for testing or debugging, consider adding a mechanism to ensure these methods are called in production to maintain the expected functionality of the Kafka consumer.

@hentrymartin hentrymartin changed the base branch from pm-1788 to feat/aiworkflows-lsb September 3, 2025 21:55
break;
}
case 'llm_model': {
console.log(`[${type}][${subtype}][${file}] Processing file`);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The log statement uses the variable file, but file is not defined within the current scope. Ensure that file is defined or passed to the function if needed.

console.log(`[${type}][${subtype}][${file}] Processing file`);
const idToLegacyIdMap = {};
const processedData = jsonData[key].map((c) => {
const id = nanoid(14);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a more descriptive variable name than c for better readability and maintainability of the code.

@@ -1509,6 +1666,9 @@ migrate()
},
{ key: 'uploadIdMap', value: uploadIdMap },
{ key: 'submissionIdMap', value: submissionIdMap },
{ key: 'llmProviderIdMap', value: llmProviderIdMap },
{ key: 'llmModelIdMap', value: llmModelIdMap },
{ key: 'aiWorkflowIdMap', value: aiWorkflowIdMap },
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is an extra comma at the end of the object in line 1671. This may lead to syntax errors in environments that do not support trailing commas. Consider removing the trailing comma.

description: 'The AI workflow has been successfully created.',
})
@ApiResponse({ status: 403, description: 'Forbidden.' })
async create(@Body() createAiWorkflowDto: CreateAiWorkflowDto) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding error handling for the create method to manage potential exceptions that might occur during the creation process. This will help in providing more informative error responses to the client.


async scorecardExists(scorecardId: string): Promise<boolean> {
const count = await this.prisma.scorecard.count({
where: { id: scorecardId, status: ScorecardStatus.ACTIVE},
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider handling the case where ScorecardStatus.ACTIVE might not be defined or imported correctly. Ensure that ScorecardStatus is imported from the correct module and that it includes the ACTIVE status to prevent runtime errors.

createdBy: string;

@ApiProperty({ required: false })
updatedBy?: string;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decorators @IsString() and @IsNotEmpty() have been removed from the updatedBy property. If updatedBy should always be a non-empty string when provided, consider keeping these decorators to enforce validation.

@hentrymartin hentrymartin self-assigned this Sep 5, 2025
updatedBy?: string;

@ApiProperty({ required: false })
updatedAt?: Date;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove createdBy, updatedBy, createdAt, updatedAt from the DTO

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hentrymartin yes, we won't need those over the API call.

updatedBy?: string;

@ApiProperty({ required: false })
updatedAt?: Date;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hentrymartin yes, we won't need those over the API call.

@hentrymartin hentrymartin changed the base branch from feat/aiworkflows-lsb to develop September 9, 2025 18:23
@hentrymartin
Copy link
Collaborator Author

@vas3a @kkartunov I've updated the PR based on the review comments. Can you please have another look on it?


return this.prisma.aiWorkflow.create({
data: {
...rest,
Copy link
Collaborator

@vas3a vas3a Sep 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you shouldn't do ...rest in here. you should extract the data you need and then pass it to the db.

@kkartunov @jmgasper this is an issue with the current global config for the ValidationPipe. Currently it is configured with whitelist: false - which will not strip off any additional data sent to the API.
This is bad IMO. like in this example, if we don't make sure to manually strip off excess data, it could be passed to DB.
It can get even uglier if the user sends fields that are not validated through DTO but they exist in db (eg. createdBy shouldn't be accepted through API, and we shouldn't add it in DTO, BUT this means that this gets sent to DB without validation).

This could be fixed by either usingwhitelist: true, but might cause other errors if someone used whitelist: false intentionally (we might do it anyway, it's dev only atm and can fix it), OR use forbidNonWhitelisted: true which will throw error if you send additional data. This should be more obvious.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do agree with @vas3a. @jmgasper we plan to have whitelist: false in the dto here. What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hentrymartin please update the code to not use ...rest but pick fields.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vas3a As the audit fields are not null fields, I am passing empty string for now to avoid type errors, once the Prisma middleware is done, then it should be removed.


return this.prisma.aiWorkflow.create({
data: {
...rest,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hentrymartin please update the code to not use ...rest but pick fields.

@hentrymartin
Copy link
Collaborator Author

@kkartunov I've updated the PR, please have a look into it again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants