From 634ee9b4b3f8bef346aff1f71cfa76f418698c94 Mon Sep 17 00:00:00 2001 From: Davidson Gomes Date: Fri, 12 Jul 2024 14:01:18 -0300 Subject: [PATCH] fix: Resolve 'no such file or directory' error (#123) This commit fixes an issue where a 'no such file or directory' error was being thrown. The error was caused by the absence of a temporary directory used for storing data. To resolve this issue, the `initStoreFolders` method was added to the `PrismaRepository` class, which creates the necessary store path and temporary directory during initialization. The modifications include changes to the `repository.service.ts` file, where the `initStoreFolders` method was implemented. The `fs` and `path` modules were imported to facilitate file system operations. With these changes, the error should no longer occur, ensuring the proper functioning of the application. --- src/api/repository/repository.service.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/api/repository/repository.service.ts b/src/api/repository/repository.service.ts index 9c9bbf0e..8f8db0c5 100644 --- a/src/api/repository/repository.service.ts +++ b/src/api/repository/repository.service.ts @@ -1,4 +1,6 @@ import { PrismaClient } from '@prisma/client'; +import fs from 'fs'; +import { join } from 'path'; import { ConfigService } from '../../config/env.config'; import { Logger } from '../../config/logger.config'; @@ -13,10 +15,29 @@ export class Query { export class PrismaRepository extends PrismaClient { constructor(private readonly configService: ConfigService) { super(); + + this.initStoreFolders(); } private readonly logger = new Logger(PrismaRepository.name); + private async initStoreFolders() { + try { + const storePath = join(process.cwd(), 'store'); + + this.logger.verbose('creating store path: ' + storePath); + + const tempDir = join(storePath, 'temp'); + + if (!fs.existsSync(tempDir)) { + this.logger.verbose('creating temp dir: ' + tempDir); + fs.mkdirSync(tempDir, { recursive: true }); + } + } catch (error) { + this.logger.error(error); + } + } + public async onModuleInit() { await this.$connect(); this.logger.info('Repository:Prisma - ON');