diff --git a/backend/src/project/dto/LinkCreateRequest.dto.ts b/backend/src/project/dto/LinkCreateRequest.dto.ts new file mode 100644 index 0000000..dee49be --- /dev/null +++ b/backend/src/project/dto/LinkCreateRequest.dto.ts @@ -0,0 +1,20 @@ +import { Type } from 'class-transformer'; +import { IsNotEmpty, IsString, Matches, ValidateNested } from 'class-validator'; + +class Link { + @IsString() + url: string; + + @IsString() + description: string; +} + +export class LinkCreateRequestDto { + @Matches(/^create$/) + action: string; + + @IsNotEmpty() + @ValidateNested() + @Type(() => Link) + content: Link; +} diff --git a/backend/src/project/websocket.gateway.ts b/backend/src/project/websocket.gateway.ts index 4483ec3..ca1b969 100644 --- a/backend/src/project/websocket.gateway.ts +++ b/backend/src/project/websocket.gateway.ts @@ -23,6 +23,7 @@ import { InitLandingResponseDto } from './dto/InitLandingResponse.dto'; import { MemoColorUpdateRequestDto } from './dto/MemoColorUpdateRequest.dto'; import { MemberUpdateRequestDto } from './dto/MemberUpdateRequest.dto'; import { MemberStatus } from './enum/MemberStatus.enum'; +import { LinkCreateRequestDto } from './dto/LinkCreateRequest.dto'; export interface ClientSocket extends Socket { projectId?: number; @@ -252,6 +253,36 @@ export class ProjectWebsocketGateway this.sendMemberStatusUpdate(client); } + @SubscribeMessage('link') + async handleLinkEvent( + @ConnectedSocket() client: ClientSocket, + @MessageBody() data: LinkCreateRequestDto, + ) { + if (data.action === 'create') { + const errors = await validate(plainToClass(LinkCreateRequestDto, data)); + if (errors.length > 0) { + const errorList = this.getRecursiveErrorMsgList(errors); + client.emit('error', { errorList }); + return; + } + const { content } = data as LinkCreateRequestDto; + const createLink = await this.projectService.createLink( + client.project, + content.url, + content.description, + ); + client.nsp.to('landing').emit('landing', { + domain: 'link', + action: 'create', + content: { + id: createLink.id, + url: createLink.url, + description: createLink.description, + }, + }); + } + } + notifyJoinToConnectedMembers(projectId: number, member: Member) { const projectNamespace = this.namespaceMap.get(projectId); if (!projectNamespace) return;