Skip to content
This repository has been archived by the owner on Mar 23, 2024. It is now read-only.

Commit

Permalink
Update file.service.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
nmashchenko committed Jun 4, 2023
1 parent 8d8a5ec commit b80eebf
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions server/src/files/file.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,6 @@ export class FileService {
});

constructor(private readonly configService: ConfigService) {}
/**
* Check if a file exists at a given path.
*
* @param {string} path
*
* @returns {boolean}
*/
checkIfFileOrDirectoryExists = (path: string): boolean => {
return fs.existsSync(path);
};

async createFile(
type: FileType,
Expand Down Expand Up @@ -116,8 +106,9 @@ export class FileService {
data: string,
): Promise<Buffer> => {
const filePath = path.resolve(__dirname, '..', 'static', FileType.TEXT);
if (!this.checkIfFileOrDirectoryExists(filePath)) {
fs.mkdirSync(filePath);
/* Creating a folder if it doesn't exist and then writing the file to the folder. */
if (!fs.existsSync(filePath)) {
fs.mkdirSync(filePath, { recursive: true });
}

const writeFile = promisify(fs.writeFile);
Expand Down

0 comments on commit b80eebf

Please sign in to comment.