From bbad09648ff5253f2f78eb508390c1f8389988d1 Mon Sep 17 00:00:00 2001 From: JongMany Date: Fri, 25 Oct 2024 10:23:10 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20ci-cd=20=ED=8C=8C=EC=9D=B4=ED=94=84?= =?UTF-8?q?=EB=9D=BC=EC=9D=B8=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/be-ci.yaml | 2 ++ src/memory/dto/edit-memory.dto.ts | 7 +++++++ src/memory/memory.controller.ts | 32 +++++++++++++++++++++++++++++++ src/memory/memory.service.ts | 17 ++++++++++++++-- 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/memory/dto/edit-memory.dto.ts diff --git a/.github/workflows/be-ci.yaml b/.github/workflows/be-ci.yaml index 03d918c..7fb32b2 100644 --- a/.github/workflows/be-ci.yaml +++ b/.github/workflows/be-ci.yaml @@ -80,6 +80,8 @@ jobs: # 실행할 작업을 정의합니다. - name: Login to Amazon ECR id: login-ecr uses: aws-actions/amazon-ecr-login@v1 + - name: Remove any existing .env.production file + run: rm -f .env.production - name: Create .env file from secrets run: | diff --git a/src/memory/dto/edit-memory.dto.ts b/src/memory/dto/edit-memory.dto.ts new file mode 100644 index 0000000..1b22331 --- /dev/null +++ b/src/memory/dto/edit-memory.dto.ts @@ -0,0 +1,7 @@ +import { IsNotEmpty, IsString } from 'class-validator'; + +export class EditMemoryDto { + @IsString() + @IsNotEmpty({ message: 'Description cannot be empty, null, or undefined.' }) + description: string; +} diff --git a/src/memory/memory.controller.ts b/src/memory/memory.controller.ts index 0ca7fa6..5964e16 100644 --- a/src/memory/memory.controller.ts +++ b/src/memory/memory.controller.ts @@ -1,13 +1,19 @@ import { + Body, Controller, Delete, Get, Param, + Put, + Res, Response, UseGuards, + UsePipes, + ValidationPipe, } from '@nestjs/common'; import { MemoryService } from './memory.service'; import { JwtAuthGuard } from 'src/auth/guard/jwt-access.guard'; +import { EditMemoryDto } from 'src/memory/dto/edit-memory.dto'; @Controller('memory') export class MemoryController { @@ -32,4 +38,30 @@ export class MemoryController { memories: memories, }); } + + @Put('/:memoryId') + @UseGuards(JwtAuthGuard) + @UsePipes(new ValidationPipe()) + async updateMemory( + @Param('memoryId') memoryId: string, + @Body() @Response() editMemoryDto: EditMemoryDto, + @Res() res, + ) { + console.log('editMemoryDto', editMemoryDto); + const memory = await this.memoryService.updateMemory( + memoryId, + editMemoryDto, + ); + if (memory) { + return res.json({ + success: true, + description: memory.description, + id: memory.id, + }); + } else { + return res.json({ + success: false, + }); + } + } } diff --git a/src/memory/memory.service.ts b/src/memory/memory.service.ts index b07ccf9..d72d65e 100644 --- a/src/memory/memory.service.ts +++ b/src/memory/memory.service.ts @@ -5,6 +5,7 @@ import { MemoryEntity } from 'src/memory/entities/memory.entity'; import { Repository } from 'typeorm'; import { UserProfileParams } from 'src/constants/function_calling'; import { UserProfileDetailEntity } from 'src/memory/entities/user-profile-detail.entity'; +import { EditMemoryDto } from 'src/memory/dto/edit-memory.dto'; @Injectable() export class MemoryService { @@ -159,11 +160,23 @@ export class MemoryService { // 변경된 MemoryEntity 저장 await this.userProfileDetailRepository.save(memory); - console.log('memory', memory); const memories = await this.userProfileDetailRepository.find({ where: { memory: memory.memory }, }); - console.log('memories', memories); return memories.filter((value) => value.isShow); } + + async updateMemory(memoryId: string, editMemoryDto: EditMemoryDto) { + const memory = await this.userProfileDetailRepository.findOne({ + where: { id: memoryId }, + }); + + if (!memory) { + throw new Error('Memory not found'); + } + + memory.description = editMemoryDto.description; + + return await this.userProfileDetailRepository.save(memory); + } }