Skip to content

Commit

Permalink
bug(api): renamed
Browse files Browse the repository at this point in the history
  • Loading branch information
tatarco committed Nov 14, 2024
1 parent 580e0b1 commit 864038e
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export class ProcessWorkflowIssuesUsecase {
await this.addTriggerIdentifierNotUniqueIfApplicable(command, issues);
this.addNameMissingIfApplicable(command, issues);
this.addDescriptionTooLongIfApplicable(command, issues);
this.addTagsIssues(command, issues);

return issues;
}
Expand Down Expand Up @@ -179,4 +180,43 @@ export class ProcessWorkflowIssuesUsecase {

return { ...workflow, issues };
}
private addTagsIssues(
command: ProcessWorkflowIssuesCommand,
issues: Record<keyof WorkflowResponseDto, RuntimeIssue[]>
) {
const tags = command.workflow.tags?.map((tag) => tag.trim());

if (!tags.length) {
return;
}

const tagsIssues: RuntimeIssue[] = [];

const duplicatedTags = tags.filter((tag, index) => tags.indexOf(tag) !== index);
const hasDuplications = duplicatedTags.length > 0;
if (hasDuplications) {
tagsIssues.push({
issueType: WorkflowIssueTypeEnum.DUPLICATED_VALUE,
message: `Duplicated tags: ${duplicatedTags.join(', ')}`,
});
}

const hasEmptyTags = tags?.some((tag) => !tag || tag === '');
if (hasEmptyTags) {
tagsIssues.push({ issueType: WorkflowIssueTypeEnum.MISSING_VALUE, message: 'Empty tag value' });
}

const exceedsMaxLength = tags?.some((tag) => tag.length > 8);
if (exceedsMaxLength) {
tagsIssues.push({
issueType: WorkflowIssueTypeEnum.LIMIT_REACHED,
message: 'Exceeded the 8 tag limit',
});
}

if (tagsIssues.length > 0) {
// eslint-disable-next-line no-param-reassign
issues.tags = tagsIssues;
}
}
}
2 changes: 2 additions & 0 deletions packages/shared/src/dto/workflows/workflow-response-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ export enum WorkflowIssueTypeEnum {
MISSING_VALUE = 'MISSING_VALUE',
MAX_LENGTH_ACCESSED = 'MAX_LENGTH_ACCESSED',
WORKFLOW_ID_ALREADY_EXISTS = 'WORKFLOW_ID_ALREADY_EXISTS',
DUPLICATED_VALUE = 'DUPLICATED_VALUE',
LIMIT_REACHED = 'LIMIT_REACHED',
}

0 comments on commit 864038e

Please sign in to comment.