mirror of
https://github.com/SyncrowIOT/backend.git
synced 2026-10-24 07:37:55 +00:00
Refactor middleware to guards for type checking
This commit is contained in:
@@ -16,6 +16,7 @@ import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
|
||||
import { AddUnitDto } from '../dtos/add.unit.dto';
|
||||
import { GetUnitChildDto } from '../dtos/get.unit.dto';
|
||||
import { UpdateUnitNameDto } from '../dtos/update.unit.dto';
|
||||
import { CheckFloorTypeGuard } from 'src/guards/floor.type.guard';
|
||||
|
||||
@ApiTags('Unit Module')
|
||||
@Controller({
|
||||
@@ -26,7 +27,7 @@ export class UnitController {
|
||||
constructor(private readonly unitService: UnitService) {}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@UseGuards(JwtAuthGuard, CheckFloorTypeGuard)
|
||||
@Post()
|
||||
async addUnit(@Body() addUnitDto: AddUnitDto) {
|
||||
try {
|
||||
|
||||
+2
-15
@@ -1,9 +1,4 @@
|
||||
import {
|
||||
MiddlewareConsumer,
|
||||
Module,
|
||||
NestModule,
|
||||
RequestMethod,
|
||||
} from '@nestjs/common';
|
||||
import { Module } from '@nestjs/common';
|
||||
import { UnitService } from './services/unit.service';
|
||||
import { UnitController } from './controllers/unit.controller';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
@@ -11,7 +6,6 @@ import { SpaceRepositoryModule } from '@app/common/modules/space/space.repositor
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { SpaceTypeRepositoryModule } from '@app/common/modules/space-type/space.type.repository.module';
|
||||
import { SpaceTypeRepository } from '@app/common/modules/space-type/repositories';
|
||||
import { CheckFloorTypeMiddleware } from 'src/middleware/CheckFloorTypeMiddleware';
|
||||
|
||||
@Module({
|
||||
imports: [ConfigModule, SpaceRepositoryModule, SpaceTypeRepositoryModule],
|
||||
@@ -19,11 +13,4 @@ import { CheckFloorTypeMiddleware } from 'src/middleware/CheckFloorTypeMiddlewar
|
||||
providers: [UnitService, SpaceRepository, SpaceTypeRepository],
|
||||
exports: [UnitService],
|
||||
})
|
||||
export class UnitModule implements NestModule {
|
||||
configure(consumer: MiddlewareConsumer) {
|
||||
consumer.apply(CheckFloorTypeMiddleware).forRoutes({
|
||||
path: '/unit',
|
||||
method: RequestMethod.POST,
|
||||
});
|
||||
}
|
||||
}
|
||||
export class UnitModule {}
|
||||
|
||||
Reference in New Issue
Block a user