Skip to content

Commit

Permalink
Merge pull request #276 from tnpfldyd/BE-fix/api
Browse files Browse the repository at this point in the history
슀페이슀 λ‚˜κ°”λ‹€ λ‹€μ‹œ λ“€μ–΄μ˜¬ 경우 λŒ€λΉ„ ν•˜μ—¬ μ½”λ“œ μˆ˜μ •
  • Loading branch information
Conut-1 authored Dec 12, 2023
2 parents 3602c19 + 1bce760 commit 43e11fd
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions nestjs-BE/server/src/base/base.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,20 @@ export abstract class BaseService<T extends HasUuid> {
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);
}
Expand Down Expand Up @@ -95,7 +103,7 @@ export abstract class BaseService<T extends HasUuid> {

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,
Expand All @@ -116,7 +124,7 @@ export abstract class BaseService<T extends HasUuid> {
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);
Expand Down

0 comments on commit 43e11fd

Please sign in to comment.