Repository navigation
fix: error handling for intent api endpoints #1560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,19 @@ | ||
| import { ApiProperty } from '@nestjs/swagger'; | ||
| import { IsNotEmpty, IsString } from 'class-validator'; | ||
|
|
||
| import { ApiProperty } from '@nestjs/swagger'; | ||
| import { Transform } from 'class-transformer'; | ||
| import { trim } from '@credebl/common/cast.helper'; | ||
|
|
||
| export class GetIntentTemplateByIntentAndOrgDto { | ||
| @ApiProperty({ example: 'WEB_CHECKIN', description: 'Intent name' }) | ||
| @IsNotEmpty() | ||
| @Transform(({ value }) => trim(value)) | ||
| @IsNotEmpty({ message: 'intentName is required' }) | ||
| @IsString() | ||
| intentName: string; | ||
|
|
||
| @ApiProperty({ example: '123e4567-e89b-12d3-a456-426614174000', description: 'Verifier Organization ID' }) | ||
| @IsNotEmpty() | ||
| @Transform(({ value }) => trim(value)) | ||
| @IsNotEmpty({ message: 'verifierOrgId is required' }) | ||
| @IsString() | ||
| verifierOrgId: string; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -579,6 +579,14 @@ export class EcosystemService { | |
|
|
||
| async getIntentTemplatesByIntentId(intentId: string): Promise<object[]> { | ||
| try { | ||
| const intent = await this.ecosystemRepository.findIntentById(intentId); | ||
|
|
||
| if (!intent) { | ||
| throw new RpcException({ | ||
| statusCode: HttpStatus.NOT_FOUND, | ||
| message: ResponseMessages.ecosystem.error.intentNotFound | ||
| }); | ||
| } | ||
| return await this.ecosystemRepository.getIntentTemplates({ intentId }); | ||
| } catch (error) { | ||
| const errorResponse = ErrorHandler.categorize(error, 'Failed to retrieve intent templates'); | ||
|
|
@@ -644,15 +652,50 @@ export class EcosystemService { | |
| data: { orgId: string; intentId: string; templateId: string; user: { id: string } } | ||
| ): Promise<object> { | ||
| try { | ||
| const { user, ...templateData } = data; | ||
| const { user, orgId, intentId, templateId } = data; | ||
|
|
||
| if (!user?.id) { | ||
| throw new RpcException({ | ||
| statusCode: HttpStatus.BAD_REQUEST, | ||
| message: 'user is required' | ||
| }); | ||
| } | ||
|
|
||
| if (!intentId || !templateId) { | ||
| throw new RpcException({ | ||
| statusCode: HttpStatus.BAD_REQUEST, | ||
| message: 'intentId and templateId are required' | ||
| }); | ||
| } | ||
|
pranalidhanavade marked this conversation as resolved.
|
||
|
|
||
| const existing = await this.ecosystemRepository.getIntentTemplateById(id); | ||
|
|
||
| if (!existing) { | ||
| throw new RpcException({ | ||
| statusCode: HttpStatus.NOT_FOUND, | ||
| message: `Intent template not found for id ${id}` | ||
| }); | ||
| } | ||
|
|
||
| const duplicate = await this.ecosystemRepository.findIntentTemplate({ | ||
| orgId, | ||
| intentId, | ||
| templateId | ||
| }); | ||
|
|
||
| if (duplicate && duplicate.id !== id) { | ||
| const scope = orgId ? `org ${orgId}` : 'globally'; | ||
|
|
||
| throw new RpcException({ | ||
| statusCode: HttpStatus.CONFLICT, | ||
| message: `A template is already assigned to this intent for ${scope}.` | ||
| }); | ||
| } | ||
|
|
||
| return await this.ecosystemRepository.updateIntentTemplate(id, { | ||
| ...templateData, | ||
| orgId, | ||
| intentId, | ||
| templateId, | ||
| lastChangedBy: user.id | ||
| }); | ||
| } catch (error) { | ||
|
|
@@ -685,11 +728,11 @@ export class EcosystemService { | |
| async createIntent(createIntentDto: CreateIntentDto): Promise<object> { | ||
| try { | ||
| const { name, description, ecosystemId, userId } = createIntentDto; | ||
| const ecosystem = await this.ecosystemRepository.getEcosystemById(ecosystemId); | ||
|
|
||
| if (!name || !ecosystemId || !userId) { | ||
| throw new BadRequestException('name, ecosystemId and userId are required'); | ||
| if (!ecosystem) { | ||
| throw new NotFoundException(ResponseMessages.ecosystem.error.ecosystemNotFound); | ||
| } | ||
|
Comment on lines
+731
to
735
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Dead code: The repository method Either remove the dead checks or change the repository to return 🤖 Prompt for AI Agents |
||
|
|
||
| return this.ecosystemRepository.createIntent({ | ||
| name, | ||
| description, | ||
|
|
@@ -715,6 +758,12 @@ export class EcosystemService { | |
| intentId?: string | ||
| ): Promise<PaginatedResponse<object>> { | ||
| try { | ||
| const ecosystem = await this.ecosystemRepository.getEcosystemById(ecosystemId); | ||
|
|
||
| if (!ecosystem) { | ||
| throw new NotFoundException(ResponseMessages.ecosystem.error.ecosystemNotFound); | ||
| } | ||
|
|
||
| return await this.ecosystemRepository.getIntents(ecosystemId, pageDetail, intentId); | ||
| } catch (error) { | ||
| const errorResponse = ErrorHandler.categorize(error, 'Failed to retrieve intents'); | ||
|
|
@@ -739,10 +788,10 @@ export class EcosystemService { | |
| */ | ||
| async updateIntent(updateIntentDto: UpdateIntentDto): Promise<object> { | ||
| try { | ||
| const { intentId, ecosystemId, userId, name, description } = updateIntentDto; | ||
| const { userId, name, description } = updateIntentDto; | ||
|
|
||
| if (!intentId || !ecosystemId || !userId) { | ||
| throw new BadRequestException('intentId, ecosystemId and userId are required'); | ||
| if (!userId) { | ||
| throw new BadRequestException(ResponseMessages.ecosystem.error.userIdMissing); | ||
| } | ||
|
pranalidhanavade marked this conversation as resolved.
|
||
|
|
||
| const intent = await this.ecosystemRepository.updateIntent({ | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.