Skip to content

Commit

Permalink
fix: Resolve 'no such file or directory' error (#123)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dgcode-tec committed Jul 12, 2024
1 parent 49ad981 commit 634ee9b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/api/repository/repository.service.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -13,10 +15,29 @@ export class Query<T> {
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');
Expand Down

0 comments on commit 634ee9b

Please sign in to comment.