added project endpoints

This commit is contained in:
hannathkadher
2024-12-09 13:26:17 +04:00
parent 5b0494b415
commit 1e5b61e3e0
6 changed files with 106 additions and 2 deletions

View File

@ -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: [
{

View File

@ -0,0 +1 @@
export * from './project.controller';

View 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
View File

@ -0,0 +1 @@
export * from './project.module';

View 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 {}

View File

@ -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 } });
}
}