mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
added project endpoints
This commit is contained in:
@ -22,6 +22,7 @@ import { VisitorPasswordModule } from './vistor-password/visitor-password.module
|
||||
import { ScheduleModule } from './schedule/schedule.module';
|
||||
import { SpaceModule } from './space/space.module';
|
||||
import { ProductModule } from './product';
|
||||
import { ProjectModule } from './project';
|
||||
@Module({
|
||||
imports: [
|
||||
ConfigModule.forRoot({
|
||||
@ -48,6 +49,7 @@ import { ProductModule } from './product';
|
||||
VisitorPasswordModule,
|
||||
ScheduleModule,
|
||||
ProductModule,
|
||||
ProjectModule,
|
||||
],
|
||||
providers: [
|
||||
{
|
||||
|
1
src/project/controllers/index.ts
Normal file
1
src/project/controllers/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './project.controller';
|
89
src/project/controllers/project.controller.ts
Normal file
89
src/project/controllers/project.controller.ts
Normal file
@ -0,0 +1,89 @@
|
||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Put,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { ProjectService } from '../services';
|
||||
import { CreateProjectDto, GetProjectParam } from '../dto';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { PaginationRequestGetListDto } from '@app/common/dto/pagination.request.dto';
|
||||
|
||||
@ApiTags('Project Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
path: ControllerRoute.PROJECT.ROUTE,
|
||||
})
|
||||
export class ProjectController {
|
||||
constructor(private readonly projectService: ProjectService) {}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.PROJECT.ACTIONS.CREATE_PROJECT_SUMMARY,
|
||||
description: ControllerRoute.PROJECT.ACTIONS.CREATE_PROJECT_DESCRIPTION,
|
||||
})
|
||||
@Post()
|
||||
async createProject(@Body() dto: CreateProjectDto): Promise<BaseResponseDto> {
|
||||
return this.projectService.createProject(dto);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.PROJECT.ACTIONS.UPDATE_PROJECT_SUMMARY,
|
||||
description: ControllerRoute.PROJECT.ACTIONS.UPDATE_PROJECT_DESCRIPTION,
|
||||
})
|
||||
@Put(':projectUuid')
|
||||
async updateProject(
|
||||
@Param() params: GetProjectParam,
|
||||
@Body() dto: CreateProjectDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
return this.projectService.updateProject(params.projectUuid, dto);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.PROJECT.ACTIONS.DELETE_PROJECT_SUMMARY,
|
||||
description: ControllerRoute.PROJECT.ACTIONS.DELETE_PROJECT_DESCRIPTION,
|
||||
})
|
||||
@Delete(':projectUuid')
|
||||
async deleteProject(
|
||||
@Param() params: GetProjectParam,
|
||||
): Promise<BaseResponseDto> {
|
||||
return this.projectService.deleteProject(params.projectUuid);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.PROJECT.ACTIONS.LIST_PROJECTS_SUMMARY,
|
||||
description: ControllerRoute.PROJECT.ACTIONS.LIST_PROJECTS_DESCRIPTION,
|
||||
})
|
||||
@Get()
|
||||
async list(
|
||||
@Query() query: PaginationRequestGetListDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
return this.projectService.listProjects(query);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.PROJECT.ACTIONS.GET_PROJECT_SUMMARY,
|
||||
description: ControllerRoute.PROJECT.ACTIONS.GET_PROJECT_DESCRIPTION,
|
||||
})
|
||||
@Get(':projectUuid')
|
||||
async findOne(@Param() params: GetProjectParam): Promise<BaseResponseDto> {
|
||||
return this.projectService.getProject(params.projectUuid);
|
||||
}
|
||||
}
|
1
src/project/index.ts
Normal file
1
src/project/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './project.module';
|
12
src/project/project.module.ts
Normal file
12
src/project/project.module.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ProjectController } from './controllers';
|
||||
import { ProjectService } from './services';
|
||||
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||
|
||||
@Module({
|
||||
imports: [],
|
||||
controllers: [ProjectController],
|
||||
providers: [ProjectService, ProjectRepository],
|
||||
exports: [ProjectService],
|
||||
})
|
||||
export class ProjectModule {}
|
@ -180,7 +180,6 @@ export class ProjectService {
|
||||
}
|
||||
|
||||
async validate(name: string): Promise<boolean> {
|
||||
const project = await this.projectRepository.findOne({ where: { name } });
|
||||
return !project;
|
||||
return await this.projectRepository.exists({ where: { name } });
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user