adjust in store files

This commit is contained in:
Davidson Gomes
2023-07-05 19:16:47 -03:00
parent db95de6731
commit 0a925df2a9
14 changed files with 54 additions and 34 deletions

View File

@@ -5,6 +5,9 @@ import { MessageUpRepository } from './messageUp.repository';
import { MongoClient } from 'mongodb';
import { WebhookRepository } from './webhook.repository';
import { AuthRepository } from './auth.repository';
import { Auth, ConfigService, Database } from '../../config/env.config';
import { execSync } from 'child_process';
import { join } from 'path';
export class RepositoryBroker {
constructor(
@@ -14,9 +17,11 @@ export class RepositoryBroker {
public readonly messageUpdate: MessageUpRepository,
public readonly webhook: WebhookRepository,
public readonly auth: AuthRepository,
private configService: ConfigService,
dbServer?: MongoClient,
) {
this.dbClient = dbServer;
this.__init_repo_without_db__();
}
private dbClient?: MongoClient;
@@ -24,4 +29,22 @@ export class RepositoryBroker {
public get dbServer() {
return this.dbClient;
}
private __init_repo_without_db__() {
if (!this.configService.get<Database>('DATABASE').ENABLED) {
const storePath = join(process.cwd(), 'store');
execSync(
`mkdir -p ${join(
storePath,
'auth',
this.configService.get<Auth>('AUTHENTICATION').TYPE,
)}`,
);
execSync(`mkdir -p ${join(storePath, 'chats')}`);
execSync(`mkdir -p ${join(storePath, 'contacts')}`);
execSync(`mkdir -p ${join(storePath, 'messages')}`);
execSync(`mkdir -p ${join(storePath, 'message-up')}`);
execSync(`mkdir -p ${join(storePath, 'webhook')}`);
}
}
}