Merge pull request #5 from w3nder/develop

fix: create store folder
This commit is contained in:
Davidson Gomes 2023-07-19 08:11:16 -03:00 committed by GitHub
commit 2d816ab92d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,12 +5,13 @@ import { MessageUpRepository } from './messageUp.repository';
import { MongoClient } from 'mongodb'; import { MongoClient } from 'mongodb';
import { WebhookRepository } from './webhook.repository'; import { WebhookRepository } from './webhook.repository';
import { ChatwootRepository } from './chatwoot.repository'; import { ChatwootRepository } from './chatwoot.repository';
import { AuthRepository } from './auth.repository'; import { AuthRepository } from './auth.repository';
import { Auth, ConfigService, Database } from '../../config/env.config'; import { Auth, ConfigService, Database } from '../../config/env.config';
import { execSync } from 'child_process'; import { execSync } from 'child_process';
import { join } from 'path'; import { join } from 'path';
import fs from 'fs';
import { Logger } from '../../config/logger.config'; import { Logger } from '../../config/logger.config';
export class RepositoryBroker { export class RepositoryBroker {
constructor( constructor(
public readonly message: MessageRepository, public readonly message: MessageRepository,
@ -23,7 +24,6 @@ export class RepositoryBroker {
private configService: ConfigService, private configService: ConfigService,
dbServer?: MongoClient, dbServer?: MongoClient,
) { ) {
this.logger.verbose('initializing repository broker');
this.dbClient = dbServer; this.dbClient = dbServer;
this.__init_repo_without_db__(); this.__init_repo_without_db__();
} }
@ -38,39 +38,46 @@ export class RepositoryBroker {
private __init_repo_without_db__() { private __init_repo_without_db__() {
this.logger.verbose('initializing repository without db'); this.logger.verbose('initializing repository without db');
if (!this.configService.get<Database>('DATABASE').ENABLED) { if (!this.configService.get<Database>('DATABASE').ENABLED) {
this.logger.verbose('database is disabled');
const storePath = join(process.cwd(), 'store'); const storePath = join(process.cwd(), 'store');
this.logger.verbose('creating store path: ' + storePath); this.logger.verbose('creating store path: ' + storePath);
execSync( try {
`mkdir -p ${join( const authDir = join(
storePath, storePath,
'auth', 'auth',
this.configService.get<Auth>('AUTHENTICATION').TYPE, this.configService.get<Auth>('AUTHENTICATION').TYPE,
)}`,
); );
const chatsDir = join(storePath, 'chats');
const contactsDir = join(storePath, 'contacts');
const messagesDir = join(storePath, 'messages');
const messageUpDir = join(storePath, 'message-up');
const webhookDir = join(storePath, 'webhook');
const chatwootDir = join(storePath, 'chatwoot');
this.logger.verbose('creating chats path: ' + join(storePath, 'chats')); // Check if directories exist, create them if not
execSync(`mkdir -p ${join(storePath, 'chats')}`); if (!fs.existsSync(authDir)) {
fs.mkdirSync(authDir, { recursive: true });
this.logger.verbose('creating contacts path: ' + join(storePath, 'contacts')); }
execSync(`mkdir -p ${join(storePath, 'contacts')}`); if (!fs.existsSync(chatsDir)) {
fs.mkdirSync(chatsDir, { recursive: true });
this.logger.verbose('creating messages path: ' + join(storePath, 'messages')); }
execSync(`mkdir -p ${join(storePath, 'messages')}`); if (!fs.existsSync(contactsDir)) {
fs.mkdirSync(contactsDir, { recursive: true });
this.logger.verbose('creating message-up path: ' + join(storePath, 'message-up')); }
execSync(`mkdir -p ${join(storePath, 'message-up')}`); if (!fs.existsSync(messagesDir)) {
fs.mkdirSync(messagesDir, { recursive: true });
this.logger.verbose('creating webhook path: ' + join(storePath, 'webhook')); }
execSync(`mkdir -p ${join(storePath, 'webhook')}`); if (!fs.existsSync(messageUpDir)) {
fs.mkdirSync(messageUpDir, { recursive: true });
this.logger.verbose('creating chatwoot path: ' + join(storePath, 'chatwoot')); }
execSync(`mkdir -p ${join(storePath, 'chatwoot')}`); if (!fs.existsSync(webhookDir)) {
fs.mkdirSync(webhookDir, { recursive: true });
this.logger.verbose('creating temp path: ' + join(storePath, 'temp')); }
execSync(`mkdir -p ${join(storePath, 'temp')}`); if (!fs.existsSync(chatwootDir)) {
fs.mkdirSync(chatwootDir, { recursive: true });
}
} catch (error) {
console.error(error);
}
} }
} }
} }