From 1bce760337dabe2838a84d3a1dbdf303ca0c85b4 Mon Sep 17 00:00:00 2001 From: tnpfldyd Date: Tue, 12 Dec 2023 18:53:12 +0900 Subject: [PATCH] =?UTF-8?q?fix(#212):=20=EC=8A=A4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=8A=A4=20=EB=82=98=EA=B0=94=EB=8B=A4=20=EB=8B=A4=EC=8B=9C=20?= =?UTF-8?q?=EB=93=A4=EC=96=B4=EC=98=AC=20=EA=B2=BD=EC=9A=B0=20=EB=8C=80?= =?UTF-8?q?=EB=B9=84=20=ED=95=98=EC=97=AC=20=EC=BD=94=EB=93=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nestjs-BE/server/src/base/base.service.ts | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/nestjs-BE/server/src/base/base.service.ts b/nestjs-BE/server/src/base/base.service.ts index c00772c1..11be3268 100644 --- a/nestjs-BE/server/src/base/base.service.ts +++ b/nestjs-BE/server/src/base/base.service.ts @@ -41,12 +41,20 @@ export abstract class BaseService { async create(data: T, generateUuidFlag: boolean = true) { if (generateUuidFlag) data.uuid = generateUuid(); const key = this.generateKey(data); - const storeData = await this.getDataFromCacheOrDB(key); - if (storeData) { - throw new HttpException('Data already exists.', HttpStatus.CONFLICT); + const deleteCommand = this.temporaryDatabaseService.get( + this.className, + key, + 'delete', + ); + if (deleteCommand) { + this.temporaryDatabaseService.delete(this.className, key, 'delete'); + } else { + const storeData = await this.getDataFromCacheOrDB(key); + if (storeData) { + throw new HttpException('Data already exists.', HttpStatus.CONFLICT); + } + this.temporaryDatabaseService.create(this.className, key, data); } - - this.temporaryDatabaseService.create(this.className, key, data); this.cache.put(key, data); return ResponseUtils.createResponse(HttpStatus.CREATED, data); } @@ -95,7 +103,7 @@ export abstract class BaseService { async remove(key: string) { const storeData = await this.getDataFromCacheOrDB(key); - if (!storeData) return; + if (!storeData) return ResponseUtils.createResponse(HttpStatus.NO_CONTENT); this.cache.delete(key); const insertTemporaryData = this.temporaryDatabaseService.get( this.className, @@ -116,7 +124,7 @@ export abstract class BaseService { const value = key.includes('+') ? this.stringToObject(key) : key; this.temporaryDatabaseService.remove(this.className, key, { field: this.field, - value: value, + value, }); } return ResponseUtils.createResponse(HttpStatus.NO_CONTENT);