|
| 1 | +import { MiddlewareConsumer, Module, RequestMethod } from '@nestjs/common'; |
| 2 | +import { TypeOrmModule } from '@nestjs/typeorm'; |
| 3 | +import { GlobalDatabaseContext } from '../../../common/application/global-database-context.js'; |
| 4 | +import { BaseType, UseCaseType } from '../../../common/data-injection.tokens.js'; |
| 5 | +import { AuthMiddleware } from '../../../authorization/auth.middleware.js'; |
| 6 | +import { UserEntity } from '../../user/user.entity.js'; |
| 7 | +import { LogOutEntity } from '../../log-out/log-out.entity.js'; |
| 8 | +import { DashboardWidgetController } from './dashboard-widgets.controller.js'; |
| 9 | +import { CreateDashboardWidgetUseCase } from './use-cases/create-dashboard-widget.use.case.js'; |
| 10 | +import { UpdateDashboardWidgetUseCase } from './use-cases/update-dashboard-widget.use.case.js'; |
| 11 | +import { DeleteDashboardWidgetUseCase } from './use-cases/delete-dashboard-widget.use.case.js'; |
| 12 | + |
| 13 | +@Module({ |
| 14 | + imports: [TypeOrmModule.forFeature([UserEntity, LogOutEntity])], |
| 15 | + providers: [ |
| 16 | + { |
| 17 | + provide: BaseType.GLOBAL_DB_CONTEXT, |
| 18 | + useClass: GlobalDatabaseContext, |
| 19 | + }, |
| 20 | + { |
| 21 | + provide: UseCaseType.CREATE_DASHBOARD_WIDGET, |
| 22 | + useClass: CreateDashboardWidgetUseCase, |
| 23 | + }, |
| 24 | + { |
| 25 | + provide: UseCaseType.UPDATE_DASHBOARD_WIDGET, |
| 26 | + useClass: UpdateDashboardWidgetUseCase, |
| 27 | + }, |
| 28 | + { |
| 29 | + provide: UseCaseType.DELETE_DASHBOARD_WIDGET, |
| 30 | + useClass: DeleteDashboardWidgetUseCase, |
| 31 | + }, |
| 32 | + ], |
| 33 | + controllers: [DashboardWidgetController], |
| 34 | + exports: [], |
| 35 | +}) |
| 36 | +export class DashboardWidgetModule { |
| 37 | + public configure(consumer: MiddlewareConsumer): void { |
| 38 | + consumer |
| 39 | + .apply(AuthMiddleware) |
| 40 | + .forRoutes( |
| 41 | + { path: '/dashboard/:dashboardId/widget/:connectionId', method: RequestMethod.POST }, |
| 42 | + { path: '/dashboard/:dashboardId/widget/:widgetId/:connectionId', method: RequestMethod.PUT }, |
| 43 | + { path: '/dashboard/:dashboardId/widget/:widgetId/:connectionId', method: RequestMethod.DELETE }, |
| 44 | + ); |
| 45 | + } |
| 46 | +} |
0 commit comments