-
-
Notifications
You must be signed in to change notification settings - Fork 18
add update connection title functionality with DTO, data structure, and controller integration #1699
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
add update connection title functionality with DTO, data structure, and controller integration #1699
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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| export class UpdateConnectionTitleDs { | ||
| connectionId: string; | ||
| userId: string; | ||
| title: string; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { ApiProperty } from '@nestjs/swagger'; | ||
| import { IsNotEmpty, IsString } from 'class-validator'; | ||
|
|
||
| export class UpdateConnectionTitleDto { | ||
| @ApiProperty() | ||
| @IsString() | ||
| @IsNotEmpty() | ||
| title: string; | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,29 @@ | ||||||||||||||||||||||||
| import { Inject, Injectable, Scope } from '@nestjs/common'; | ||||||||||||||||||||||||
| import AbstractUseCase from '../../../common/abstract-use.case.js'; | ||||||||||||||||||||||||
| import { IGlobalDatabaseContext } from '../../../common/application/global-database-context.interface.js'; | ||||||||||||||||||||||||
| import { BaseType } from '../../../common/data-injection.tokens.js'; | ||||||||||||||||||||||||
| import { SuccessResponse } from '../../../microservices/saas-microservice/data-structures/common-responce.ds.js'; | ||||||||||||||||||||||||
| import { UpdateConnectionTitleDs } from '../application/data-structures/update-connection-title.ds.js'; | ||||||||||||||||||||||||
| import { IUpdateConnectionTitle } from './use-cases.interfaces.js'; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| @Injectable({ scope: Scope.REQUEST }) | ||||||||||||||||||||||||
| export class UpdateConnectionTitleUseCase | ||||||||||||||||||||||||
| extends AbstractUseCase<UpdateConnectionTitleDs, SuccessResponse> | ||||||||||||||||||||||||
| implements IUpdateConnectionTitle | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| constructor( | ||||||||||||||||||||||||
| @Inject(BaseType.GLOBAL_DB_CONTEXT) | ||||||||||||||||||||||||
| protected _dbContext: IGlobalDatabaseContext, | ||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||
| super(); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| protected async implementation(inputData: UpdateConnectionTitleDs): Promise<SuccessResponse> { | ||||||||||||||||||||||||
| const { connectionId, title } = inputData; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const connection = await this._dbContext.connectionRepository.findOne({ where: { id: connectionId } }); | ||||||||||||||||||||||||
| connection.title = title; | ||||||||||||||||||||||||
| await this._dbContext.connectionRepository.save(connection); | ||||||||||||||||||||||||
|
Comment on lines
+24
to
+26
|
||||||||||||||||||||||||
| const connection = await this._dbContext.connectionRepository.findOne({ where: { id: connectionId } }); | |
| connection.title = title; | |
| await this._dbContext.connectionRepository.save(connection); | |
| const updateResult = await this._dbContext.connectionRepository.update( | |
| { id: connectionId }, | |
| { title }, | |
| ); | |
| if (!updateResult.affected) { | |
| throw new Error(`Connection with id ${connectionId} not found`); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
findOnemay returnnullwhen the connectionId doesn't exist; the next line will throw (attempting to setconnection.title) and the endpoint will respond with a 500. Please handle the not-found case explicitly (e.g., throwNotFoundException(Messages.CONNECTION_NOT_FOUND)/BadRequestException, consistent with other connection use-cases) before mutating/saving.