From 95203278cde1288b1a321b189ccb161bb59622b8 Mon Sep 17 00:00:00 2001 From: tnpfldyd Date: Mon, 27 Nov 2023 16:36:11 +0900 Subject: [PATCH] =?UTF-8?q?fix(#58):=20=ED=8C=8C=EC=9D=BC=20=EC=9D=BD?= =?UTF-8?q?=EA=B3=A0=20=EC=93=B0=EA=B8=B0=20=EB=B9=84=EB=8F=99=EA=B8=B0=20?= =?UTF-8?q?=EC=B2=98=EB=A6=AC=20=EB=B0=8F=20=EC=9D=BC=EB=B6=80=20any=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/profiles/profiles.service.ts | 2 +- .../cache-server/src/spaces/spaces.service.ts | 2 +- .../temporary-database.service.ts | 21 ++++++++++--------- .../cache-server/src/users/users.service.ts | 2 +- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/nestjs-BE/cache-server/src/profiles/profiles.service.ts b/nestjs-BE/cache-server/src/profiles/profiles.service.ts index 26d0ef82..b06866d3 100644 --- a/nestjs-BE/cache-server/src/profiles/profiles.service.ts +++ b/nestjs-BE/cache-server/src/profiles/profiles.service.ts @@ -21,7 +21,7 @@ export class ProfilesService extends BaseService { }); } - generateKey(data: any): string { + generateKey(data: UpdateProfileDto): string { return data.uuid; } diff --git a/nestjs-BE/cache-server/src/spaces/spaces.service.ts b/nestjs-BE/cache-server/src/spaces/spaces.service.ts index 25ef860b..8294e8b4 100644 --- a/nestjs-BE/cache-server/src/spaces/spaces.service.ts +++ b/nestjs-BE/cache-server/src/spaces/spaces.service.ts @@ -20,7 +20,7 @@ export class SpacesService extends BaseService { }); } - generateKey(data: any): string { + generateKey(data: UpdateSpaceDto): string { return data.uuid; } diff --git a/nestjs-BE/cache-server/src/temporary-database/temporary-database.service.ts b/nestjs-BE/cache-server/src/temporary-database/temporary-database.service.ts index 5946274a..4ef8f7f3 100644 --- a/nestjs-BE/cache-server/src/temporary-database/temporary-database.service.ts +++ b/nestjs-BE/cache-server/src/temporary-database/temporary-database.service.ts @@ -1,7 +1,7 @@ import { Injectable } from '@nestjs/common'; import { PrismaService } from '../prisma/prisma.service'; import { Cron } from '@nestjs/schedule'; -import { writeFileSync, readFileSync, existsSync, readdirSync } from 'fs'; +import { promises as fs } from 'fs'; import { join } from 'path'; interface OperationData { @@ -35,8 +35,8 @@ export class TemporaryDatabaseService { }); } - private readDataFromFiles() { - const files = readdirSync(this.FOLDER_NAME); + private async readDataFromFiles() { + const files = await fs.readdir(this.FOLDER_NAME); files.forEach((file) => { if (file.endsWith('.csv')) { this.readDataFromFile(file); @@ -44,10 +44,10 @@ export class TemporaryDatabaseService { }); } - private readDataFromFile(file: string) { + private async readDataFromFile(file: string) { const [service, commandWithExtension] = file.split('-'); const command = commandWithExtension.replace('.csv', ''); - const fileData = readFileSync(join(this.FOLDER_NAME, file), 'utf8'); + const fileData = await fs.readFile(join(this.FOLDER_NAME, file), 'utf8'); fileData.split('\n').forEach((line) => { if (line.trim() !== '') { const [uniqueKey, ...dataParts] = line.split(','); @@ -82,10 +82,11 @@ export class TemporaryDatabaseService { operation({ service, uniqueKey, command, data }: OperationData) { const filePath = join(this.FOLDER_NAME, `${service}-${command}.csv`); - let fileData = existsSync(filePath) ? readFileSync(filePath, 'utf8') : ''; - fileData += `${uniqueKey},${JSON.stringify(data)}\n`; - writeFileSync(filePath, fileData); - this.database.get(service).get(command).set(uniqueKey, data); + fs.readFile(filePath, 'utf8').then((fileData) => { + fileData += `${uniqueKey},${JSON.stringify(data)}\n`; + fs.writeFile(filePath, fileData); + this.database.get(service).get(command).set(uniqueKey, data); + }); } @Cron('0 */10 * * * *') @@ -151,7 +152,7 @@ export class TemporaryDatabaseService { } private clearFile(filename: string) { - writeFileSync(join(this.FOLDER_NAME, filename), '', 'utf8'); + fs.writeFile(join(this.FOLDER_NAME, filename), '', 'utf8'); } getUserProfiles(user_id: string): string[] { diff --git a/nestjs-BE/cache-server/src/users/users.service.ts b/nestjs-BE/cache-server/src/users/users.service.ts index c3fd626d..3eac8ed7 100644 --- a/nestjs-BE/cache-server/src/users/users.service.ts +++ b/nestjs-BE/cache-server/src/users/users.service.ts @@ -20,7 +20,7 @@ export class UsersService extends BaseService { }); } - generateKey(data: any): string { + generateKey(data: UpdateUserDto): string { return data.email; }