Skip to content

Commit

Permalink
fix: reorganization of files and folders
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidsonGomes committed Apr 12, 2024
1 parent eb04c3f commit 94f5c13
Show file tree
Hide file tree
Showing 33 changed files with 73 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Logger } from '../../config/logger.config';
import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../../../dto/instance.dto';
import { ChamaaiDto } from '../dto/chamaai.dto';
import { InstanceDto } from '../dto/instance.dto';
import { ChamaaiService } from '../services/chamaai.service';

const logger = new Logger('ChamaaiController');
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Schema } from 'mongoose';

import { dbserver } from '../../libs/db.connect';
import { dbserver } from '../../../../libs/db.connect';

export class ChamaaiRaw {
_id?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { readFileSync } from 'fs';
import { join } from 'path';

import { ConfigService } from '../../config/env.config';
import { Logger } from '../../config/logger.config';
import { IInsert, Repository } from '../abstract/abstract.repository';
import { ChamaaiRaw, IChamaaiModel } from '../models';
import { ConfigService } from '../../../../config/env.config';
import { Logger } from '../../../../config/logger.config';
import { IInsert, Repository } from '../../../abstract/abstract.repository';
import { ChamaaiRaw, IChamaaiModel } from '../../../models';

export class ChamaaiRepository extends Repository {
constructor(private readonly chamaaiModel: IChamaaiModel, private readonly configService: ConfigService) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { RequestHandler, Router } from 'express';

import { Logger } from '../../config/logger.config';
import { chamaaiSchema, instanceNameSchema } from '../../validate/validate.schema';
import { RouterBroker } from '../abstract/abstract.router';
import { Logger } from '../../../../config/logger.config';
import { chamaaiSchema, instanceNameSchema } from '../../../../validate/validate.schema';
import { RouterBroker } from '../../../abstract/abstract.router';
import { InstanceDto } from '../../../dto/instance.dto';
import { HttpStatus } from '../../../routes/index.router';
import { chamaaiController } from '../../../server.module';
import { ChamaaiDto } from '../dto/chamaai.dto';
import { InstanceDto } from '../dto/instance.dto';
import { chamaaiController } from '../server.module';
import { HttpStatus } from './index.router';

const logger = new Logger('ChamaaiRouter');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ import axios from 'axios';
import { writeFileSync } from 'fs';
import path from 'path';

import { ConfigService, HttpServer } from '../../config/env.config';
import { Logger } from '../../config/logger.config';
import { ConfigService, HttpServer } from '../../../../config/env.config';
import { Logger } from '../../../../config/logger.config';
import { InstanceDto } from '../../../dto/instance.dto';
import { ChamaaiRaw } from '../../../models';
import { WAMonitoringService } from '../../../services/monitor.service';
import { Events } from '../../../types/wa.types';
import { ChamaaiDto } from '../dto/chamaai.dto';
import { InstanceDto } from '../dto/instance.dto';
import { ChamaaiRaw } from '../models';
import { Events } from '../types/wa.types';
import { WAMonitoringService } from './monitor.service';

export class ChamaaiService {
constructor(private readonly waMonitor: WAMonitoringService, private readonly configService: ConfigService) {}
Expand Down
35 changes: 35 additions & 0 deletions src/api/integrations/chamaai/validate/chamaai.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { JSONSchema7 } from 'json-schema';
import { v4 } from 'uuid';

const isNotEmpty = (...propertyNames: string[]): JSONSchema7 => {
const properties = {};
propertyNames.forEach(
(property) =>
(properties[property] = {
minLength: 1,
description: `The "${property}" cannot be empty`,
}),
);
return {
if: {
propertyNames: {
enum: [...propertyNames],
},
},
then: { properties },
};
};

export const chamaaiSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
enabled: { type: 'boolean', enum: [true, false] },
url: { type: 'string' },
token: { type: 'string' },
waNumber: { type: 'string' },
answerByAudio: { type: 'boolean', enum: [true, false] },
},
required: ['enabled', 'url', 'token', 'waNumber', 'answerByAudio'],
...isNotEmpty('enabled', 'url', 'token', 'waNumber', 'answerByAudio'),
};
2 changes: 1 addition & 1 deletion src/api/integrations/chatwoot/routes/chatwoot.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Logger } from '../../../../config/logger.config';
import { chatwootSchema, instanceNameSchema } from '../../../../validate/validate.schema';
import { RouterBroker } from '../../../abstract/abstract.router';
import { InstanceDto } from '../../../dto/instance.dto';
import { HttpStatus } from '../../../routers/index.router';
import { HttpStatus } from '../../../routes/index.router';
import { chatwootController } from '../../../server.module';
import { ChatwootDto } from '../dto/chatwoot.dto';

Expand Down
2 changes: 1 addition & 1 deletion src/api/integrations/rabbitmq/routes/rabbitmq.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Logger } from '../../../../config/logger.config';
import { instanceNameSchema, rabbitmqSchema } from '../../../../validate/validate.schema';
import { RouterBroker } from '../../../abstract/abstract.router';
import { InstanceDto } from '../../../dto/instance.dto';
import { HttpStatus } from '../../../routers/index.router';
import { HttpStatus } from '../../../routes/index.router';
import { rabbitmqController } from '../../../server.module';
import { RabbitmqDto } from '../dto/rabbitmq.dto';

Expand Down
2 changes: 1 addition & 1 deletion src/api/integrations/sqs/routes/sqs.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Logger } from '../../../../config/logger.config';
import { instanceNameSchema, sqsSchema } from '../../../../validate/validate.schema';
import { RouterBroker } from '../../../abstract/abstract.router';
import { InstanceDto } from '../../../dto/instance.dto';
import { HttpStatus } from '../../../routers/index.router';
import { HttpStatus } from '../../../routes/index.router';
import { sqsController } from '../../../server.module';
import { SqsDto } from '../dto/sqs.dto';

Expand Down
2 changes: 1 addition & 1 deletion src/api/integrations/typebot/routes/typebot.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
} from '../../../../validate/validate.schema';
import { RouterBroker } from '../../../abstract/abstract.router';
import { InstanceDto } from '../../../dto/instance.dto';
import { HttpStatus } from '../../../routers/index.router';
import { HttpStatus } from '../../../routes/index.router';
import { typebotController } from '../../../server.module';
import { TypebotDto } from '../dto/typebot.dto';

Expand Down
2 changes: 1 addition & 1 deletion src/api/integrations/websocket/routes/websocket.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Logger } from '../../../../config/logger.config';
import { instanceNameSchema, websocketSchema } from '../../../../validate/validate.schema';
import { RouterBroker } from '../../../abstract/abstract.router';
import { InstanceDto } from '../../../dto/instance.dto';
import { HttpStatus } from '../../../routers/index.router';
import { HttpStatus } from '../../../routes/index.router';
import { websocketController } from '../../../server.module';
import { WebsocketDto } from '../dto/websocket.dto';

Expand Down
2 changes: 1 addition & 1 deletion src/api/models/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
export * from '../integrations/chamaai/models/chamaai.model';
export * from '../integrations/chatwoot/models/chatwoot.model';
export * from '../integrations/rabbitmq/models/rabbitmq.model';
export * from '../integrations/sqs/models/sqs.model';
export * from '../integrations/typebot/models/typebot.model';
export * from '../integrations/websocket/models/websocket.model';
export * from './auth.model';
export * from './chamaai.model';
export * from './chat.model';
export * from './contact.model';
export * from './integration.model';
Expand Down
2 changes: 1 addition & 1 deletion src/api/repository/repository.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import { join } from 'path';

import { Auth, ConfigService, Database } from '../../config/env.config';
import { Logger } from '../../config/logger.config';
import { ChamaaiRepository } from '../integrations/chamaai/repository/chamaai.repository';
import { ChatwootRepository } from '../integrations/chatwoot/repository/chatwoot.repository';
import { RabbitmqRepository } from '../integrations/rabbitmq/repository/rabbitmq.repository';
import { SqsRepository } from '../integrations/sqs/repository/sqs.repository';
import { TypebotRepository } from '../integrations/typebot/repository/typebot.repository';
import { WebsocketRepository } from '../integrations/websocket/repository/websocket.repository';
import { AuthRepository } from './auth.repository';
import { ChamaaiRepository } from './chamaai.repository';
import { ChatRepository } from './chat.repository';
import { ContactRepository } from './contact.repository';
import { IntegrationRepository } from './integration.repository';
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import fs from 'fs';
import { Auth, configService } from '../../config/env.config';
import { authGuard } from '../guards/auth.guard';
import { instanceExistsGuard, instanceLoggedGuard } from '../guards/instance.guard';
import { ChamaaiRouter } from '../integrations/chamaai/routes/chamaai.router';
import { ChatwootRouter } from '../integrations/chatwoot/routes/chatwoot.router';
import { RabbitmqRouter } from '../integrations/rabbitmq/routes/rabbitmq.router';
import { SqsRouter } from '../integrations/sqs/routes/sqs.router';
import { TypebotRouter } from '../integrations/typebot/routes/typebot.router';
import { WebsocketRouter } from '../integrations/websocket/routes/websocket.router';
import { ChamaaiRouter } from './chamaai.router';
import { ChatRouter } from './chat.router';
import { GroupRouter } from './group.router';
import { InstanceRouter } from './instance.router';
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/api/server.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { eventEmitter } from '../config/event.config';
import { Logger } from '../config/logger.config';
import { dbserver } from '../libs/db.connect';
import { RedisCache } from '../libs/redis.client';
import { ChamaaiController } from './controllers/chamaai.controller';
import { ChatController } from './controllers/chat.controller';
import { GroupController } from './controllers/group.controller';
import { InstanceController } from './controllers/instance.controller';
Expand All @@ -12,6 +11,9 @@ import { ProxyController } from './controllers/proxy.controller';
import { SendMessageController } from './controllers/sendMessage.controller';
import { SettingsController } from './controllers/settings.controller';
import { WebhookController } from './controllers/webhook.controller';
import { ChamaaiController } from './integrations/chamaai/controllers/chamaai.controller';
import { ChamaaiRepository } from './integrations/chamaai/repository/chamaai.repository';
import { ChamaaiService } from './integrations/chamaai/services/chamaai.service';
import { CacheEngine } from './integrations/chatwoot/cache/cacheengine';
import { ChatwootController } from './integrations/chatwoot/controllers/chatwoot.controller';
import { ChatwootRepository } from './integrations/chatwoot/repository/chatwoot.repository';
Expand Down Expand Up @@ -47,7 +49,6 @@ import {
} from './models';
import { LabelModel } from './models/label.model';
import { AuthRepository } from './repository/auth.repository';
import { ChamaaiRepository } from './repository/chamaai.repository';
import { ChatRepository } from './repository/chat.repository';
import { ContactRepository } from './repository/contact.repository';
import { IntegrationRepository } from './repository/integration.repository';
Expand All @@ -60,7 +61,6 @@ import { SettingsRepository } from './repository/settings.repository';
import { WebhookRepository } from './repository/webhook.repository';
import { AuthService } from './services/auth.service';
import { CacheService } from './services/cache.service';
import { ChamaaiService } from './services/chamaai.service';
import { IntegrationService } from './services/integration.service';
import { WAMonitoringService } from './services/monitor.service';
import { ProxyService } from './services/proxy.service';
Expand Down
2 changes: 1 addition & 1 deletion src/api/services/whatsapp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { Logger } from '../../config/logger.config';
import { ROOT_DIR } from '../../config/path.config';
import { NotFoundException } from '../../exceptions';
import { ChamaaiService } from '../integrations/chamaai/services/chamaai.service';
import { ChatwootRaw } from '../integrations/chatwoot/models/chatwoot.model';
import { ChatwootService } from '../integrations/chatwoot/services/chatwoot.service';
import { getAMQP, removeQueues } from '../integrations/rabbitmq/libs/amqp.server';
Expand All @@ -36,7 +37,6 @@ import { RepositoryBroker } from '../repository/repository.manager';
import { waMonitor } from '../server.module';
import { Events, wa } from '../types/wa.types';
import { CacheService } from './cache.service';
import { ChamaaiService } from './chamaai.service';

export class WAStartupService {
constructor(
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/400.exception.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpStatus } from '../api/routers/index.router';
import { HttpStatus } from '../api/routes/index.router';

export class BadRequestException {
constructor(...objectError: any[]) {
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/401.exception.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpStatus } from '../api/routers/index.router';
import { HttpStatus } from '../api/routes/index.router';

export class UnauthorizedException {
constructor(...objectError: any[]) {
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/403.exception.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpStatus } from '../api/routers/index.router';
import { HttpStatus } from '../api/routes/index.router';

export class ForbiddenException {
constructor(...objectError: any[]) {
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/404.exception.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpStatus } from '../api/routers/index.router';
import { HttpStatus } from '../api/routes/index.router';

export class NotFoundException {
constructor(...objectError: any[]) {
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/500.exception.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { HttpStatus } from '../api/routers/index.router';
import { HttpStatus } from '../api/routes/index.router';

export class InternalServerErrorException {
constructor(...objectError: any[]) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { join } from 'path';
import { initAMQP } from './api/integrations/rabbitmq/libs/amqp.server';
import { initSQS } from './api/integrations/sqs/libs/sqs.server';
import { initIO } from './api/integrations/websocket/libs/socket.server';
import { HttpStatus, router } from './api/routers/index.router';
import { HttpStatus, router } from './api/routes/index.router';
import { waMonitor } from './api/server.module';
import { Auth, configService, Cors, HttpServer, Rabbitmq, Sqs, Webhook } from './config/env.config';
import { onUnexpectedError } from './config/error.config';
Expand Down
15 changes: 1 addition & 14 deletions src/validate/validate.schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { JSONSchema7, JSONSchema7Definition } from 'json-schema';
import { v4 } from 'uuid';

// Integrations Schema
export * from '../api/integrations/chamaai/validate/chamaai.schema';
export * from '../api/integrations/chatwoot/validate/chatwoot.schema';
export * from '../api/integrations/rabbitmq/validate/rabbitmq.schema';
export * from '../api/integrations/sqs/validate/sqs.schema';
Expand Down Expand Up @@ -1046,20 +1047,6 @@ export const proxySchema: JSONSchema7 = {
...isNotEmpty('enabled', 'proxy'),
};

export const chamaaiSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
properties: {
enabled: { type: 'boolean', enum: [true, false] },
url: { type: 'string' },
token: { type: 'string' },
waNumber: { type: 'string' },
answerByAudio: { type: 'boolean', enum: [true, false] },
},
required: ['enabled', 'url', 'token', 'waNumber', 'answerByAudio'],
...isNotEmpty('enabled', 'url', 'token', 'waNumber', 'answerByAudio'),
};

export const handleLabelSchema: JSONSchema7 = {
$id: v4(),
type: 'object',
Expand Down

0 comments on commit 94f5c13

Please sign in to comment.