Skip to content

Commit

Permalink
clean module import
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannbr committed Nov 18, 2024
1 parent 3db1b33 commit 9056e63
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 49 deletions.
10 changes: 5 additions & 5 deletions apiv2/src/App.module.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import { Global, Logger, MiddlewareConsumer, Module } from "@nestjs/common";
import configuration from "./config/configuration";
import { Logger, MiddlewareConsumer, Module } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { SentryModule } from "@sentry/nestjs/setup";
import configuration from "./config/configuration";

import { QueueModule } from "@infra/Queue.module";
import { AdminModule } from "./admin/Admin.module";
import { LoggerRequestMiddleware } from "./shared/infra/LoggerRequest.middleware";
import { CorrelationIdMiddleware } from "./shared/infra/CorrelationId.middleware.js";
import { SharedModule } from "./shared/Shared.module";
import { TaskModule } from "./task/Task.module";
import { LoggerRequestMiddleware } from "./shared/infra/LoggerRequest.middleware";

@Module({
imports: [
Expand All @@ -16,6 +15,7 @@ import { TaskModule } from "./task/Task.module";
}),
SentryModule.forRoot(),
AdminModule,
QueueModule,
],
controllers: [],
providers: [Logger],
Expand Down
11 changes: 11 additions & 0 deletions apiv2/src/MainJob.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { Module } from "@nestjs/common";
import { NotificationJobModule } from "@notification/NotificationJob.module";
import { AdminJobModule } from "./admin/AdminJob.module";
import configuration from "@config/configuration";
import { ConfigModule } from "@nestjs/config";
import { QueueModule } from "@infra/Queue.module";

@Module({
imports: [QueueModule, NotificationJobModule, AdminJobModule],
})
export class MainJobModule {}
19 changes: 2 additions & 17 deletions apiv2/src/admin/Admin.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,25 +29,10 @@ import { AdminTaskRepository } from "./infra/task/AdminTaskMongo.repository";
import { QueueType } from "@shared/infra/Queue";
import { taskMongoProviders } from "@task/infra/TaskMongo.provider";
import { AdminTaskController } from "./infra/task/api/AdminTask.controller";
import { QueueModule } from "@infra/Queue.module";

@Module({
imports: [
ClsModule.forRoot({}),
ConfigModule,
DatabaseModule, //TO REMOVE ?
JwtAuthModule,
NotificationModule,
BullModule.registerQueue({
name: NotificationQueueType.EMAIL,
}),
BullModule.registerQueue({
name: NotificationQueueType.CONTACT,
}),
BullModule.registerQueue({
name: QueueType.ADMIN_TASK,
}),
TaskModule,
],
imports: [ClsModule.forRoot({}), DatabaseModule, JwtAuthModule, NotificationModule, QueueModule, TaskModule],
controllers: [ClasseController, AuthController, AdminTaskController],
providers: [
ClasseService,
Expand Down
22 changes: 5 additions & 17 deletions apiv2/src/admin/AdminJob.module.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
import { Logger, Module } from "@nestjs/common";
import { AdminTaskConsumer } from "./infra/task/AdminTask.consumer";
import { AdminTaskRepository } from "./infra/task/AdminTaskMongo.repository";
import configuration from "@config/configuration";
import { DatabaseModule } from "@infra/Database.module";
import { QueueModule } from "@infra/Queue.module";
import { Logger, Module } from "@nestjs/common";
import { ConfigModule } from "@nestjs/config";
import { DatabaseModule } from "@infra/Database.module";
import { TaskModule } from "@task/Task.module";
import { taskMongoProviders } from "@task/infra/TaskMongo.provider";
import { BullModule } from "@nestjs/bullmq";
import { QueueType } from "@shared/infra/Queue";
import { AdminTaskConsumer } from "./infra/task/AdminTask.consumer";
import { AdminTaskRepository } from "./infra/task/AdminTaskMongo.repository";

@Module({
imports: [
TaskModule,
DatabaseModule,
ConfigModule.forRoot({
load: [configuration],
}),
QueueModule,
BullModule.registerQueue({
name: QueueType.ADMIN_TASK,
}),
],
imports: [TaskModule, DatabaseModule],
providers: [
Logger,
AdminTaskConsumer,
Expand Down
6 changes: 5 additions & 1 deletion apiv2/src/infra/Queue.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ConfigModule, ConfigService } from "@nestjs/config";

import { BullModule } from "@nestjs/bullmq";
import { Module } from "@nestjs/common";
import { Global, Module } from "@nestjs/common";
import { NotificationQueueType } from "@notification/infra/Notification";
import { QueueType } from "@shared/infra/Queue";

@Global()
@Module({
imports: [
BullModule.forRootAsync({
Expand All @@ -22,6 +23,9 @@ import { QueueType } from "@shared/infra/Queue";
BullModule.registerQueue({
name: NotificationQueueType.CONTACT,
}),
BullModule.registerQueue({
name: QueueType.ADMIN_TASK,
}),
],
exports: [BullModule],
})
Expand Down
1 change: 0 additions & 1 deletion apiv2/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ConfigService } from "@nestjs/config";
import { ValidationPipe } from "@nestjs/common";
import { NestFactory } from "@nestjs/core";
import { AppModule } from "./App.module";
import { NotificationJobModule } from "./notification/NotificationJob.module";

async function bootstrap() {
const app = await NestFactory.create(AppModule);
Expand Down
8 changes: 3 additions & 5 deletions apiv2/src/mainJob.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import "./instrument"; // first

import { NestFactory } from "@nestjs/core";
import { NotificationJobModule } from "./notification/NotificationJob.module";
import { Logger } from "@nestjs/common";
import { AdminJobModule } from "./admin/AdminJob.module";
import { NestFactory } from "@nestjs/core";
import { MainJobModule } from "./MainJob.module";

async function bootstrap() {
await NestFactory.createApplicationContext(NotificationJobModule);
await NestFactory.createApplicationContext(AdminJobModule);
await NestFactory.createApplicationContext(MainJobModule);
Logger.log(`Job started`, "bootstrap mainJob");
// TODO: handle logs error here ?
// process.on("uncaughtException", (error) => {
Expand Down
2 changes: 1 addition & 1 deletion apiv2/src/notification/Notification.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { ContactProducer } from "./infra/email/Contact.producer";
import { NotificationProducer } from "./infra/Notification.producer";

@Module({
imports: [QueueModule, SharedModule],
imports: [SharedModule],
providers: [
{
provide: NotificationGateway,
Expand Down
1 change: 0 additions & 1 deletion apiv2/src/notification/NotificationJob.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { contactFactory, emailFactory } from "./infra/email/brevo/EmailContact.f
ConfigModule.forRoot({
load: [configuration],
}),
QueueModule,
],
providers: [Logger, EmailConsumer, ContactConsumer, emailFactory, contactFactory],
})
Expand Down
1 change: 0 additions & 1 deletion apiv2/src/task/infra/TaskMongo.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export class TaskRepository implements TaskGateway {
}

async toSuccess(id: string): Promise<TaskModel> {
// TODO: check if task exists and is in progress
const updatedTask = await this.taskMongooseEntity.findByIdAndUpdate(
id,
{ status: TaskStatus.COMPLETED },
Expand Down

0 comments on commit 9056e63

Please sign in to comment.