From df80928b68ec128450698ce8c4927cefb064995f Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Mon, 9 Dec 2024 10:51:58 +0400 Subject: [PATCH 01/10] created project entity --- libs/common/src/database/database.module.ts | 3 ++- libs/common/src/modules/project/dtos/index.ts | 1 + .../src/modules/project/dtos/project.dto.ts | 15 ++++++++++++ .../src/modules/project/entities/index.ts | 1 + .../project/entities/project.entity.ts | 23 +++++++++++++++++++ libs/common/src/modules/project/index.ts | 1 + .../project/project.repository.module.ts | 11 +++++++++ .../modules/project/repositiories/index.ts | 1 + .../repositiories/project.repository.ts | 10 ++++++++ 9 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 libs/common/src/modules/project/dtos/index.ts create mode 100644 libs/common/src/modules/project/dtos/project.dto.ts create mode 100644 libs/common/src/modules/project/entities/index.ts create mode 100644 libs/common/src/modules/project/entities/project.entity.ts create mode 100644 libs/common/src/modules/project/index.ts create mode 100644 libs/common/src/modules/project/project.repository.module.ts create mode 100644 libs/common/src/modules/project/repositiories/index.ts create mode 100644 libs/common/src/modules/project/repositiories/project.repository.ts diff --git a/libs/common/src/database/database.module.ts b/libs/common/src/database/database.module.ts index 8b4acf4..34e4bb6 100644 --- a/libs/common/src/database/database.module.ts +++ b/libs/common/src/database/database.module.ts @@ -27,7 +27,7 @@ import { DeviceStatusLogEntity } from '../modules/device-status-log/entities'; import { SceneEntity, SceneIconEntity } from '../modules/scene/entities'; import { SceneDeviceEntity } from '../modules/scene-device/entities'; import { SpaceProductEntity } from '../modules/space/entities/space-product.entity'; - +import { ProjectEntity } from '../modules/project/entities'; @Module({ imports: [ TypeOrmModule.forRootAsync({ @@ -42,6 +42,7 @@ import { SpaceProductEntity } from '../modules/space/entities/space-product.enti password: configService.get('DB_PASSWORD'), database: configService.get('DB_NAME'), entities: [ + ProjectEntity, UserEntity, UserSessionEntity, UserOtpEntity, diff --git a/libs/common/src/modules/project/dtos/index.ts b/libs/common/src/modules/project/dtos/index.ts new file mode 100644 index 0000000..9d264cb --- /dev/null +++ b/libs/common/src/modules/project/dtos/index.ts @@ -0,0 +1 @@ +export * from './project.dto'; diff --git a/libs/common/src/modules/project/dtos/project.dto.ts b/libs/common/src/modules/project/dtos/project.dto.ts new file mode 100644 index 0000000..a5931af --- /dev/null +++ b/libs/common/src/modules/project/dtos/project.dto.ts @@ -0,0 +1,15 @@ +import { ApiProperty } from '@nestjs/swagger'; + +export class ProjectDto { + @ApiProperty({ + example: 'd7a44e8a-32d5-4f39-ae2e-013f1245aead', + description: 'UUID of the project', + }) + uuid: string; + + @ApiProperty({ + example: 'Project 1', + description: 'Name of the project', + }) + name: string; +} diff --git a/libs/common/src/modules/project/entities/index.ts b/libs/common/src/modules/project/entities/index.ts new file mode 100644 index 0000000..bd8d161 --- /dev/null +++ b/libs/common/src/modules/project/entities/index.ts @@ -0,0 +1 @@ +export * from './project.entity'; diff --git a/libs/common/src/modules/project/entities/project.entity.ts b/libs/common/src/modules/project/entities/project.entity.ts new file mode 100644 index 0000000..f614b50 --- /dev/null +++ b/libs/common/src/modules/project/entities/project.entity.ts @@ -0,0 +1,23 @@ +import { Entity, Column } from 'typeorm'; +import { AbstractEntity } from '../../abstract/entities/abstract.entity'; +import { ProjectDto } from '../dtos'; + +@Entity({ name: 'project' }) +export class ProjectEntity extends AbstractEntity { + @Column({ + type: 'uuid', + default: () => 'gen_random_uuid()', + nullable: false, + }) + public project_id: string; + + @Column({ + nullable: false, + }) + public name: string; + + constructor(partial: Partial) { + super(); + Object.assign(this, partial); + } +} diff --git a/libs/common/src/modules/project/index.ts b/libs/common/src/modules/project/index.ts new file mode 100644 index 0000000..cacdb88 --- /dev/null +++ b/libs/common/src/modules/project/index.ts @@ -0,0 +1 @@ +export * from './project.repository.module'; diff --git a/libs/common/src/modules/project/project.repository.module.ts b/libs/common/src/modules/project/project.repository.module.ts new file mode 100644 index 0000000..0b744f8 --- /dev/null +++ b/libs/common/src/modules/project/project.repository.module.ts @@ -0,0 +1,11 @@ +import { Module } from '@nestjs/common'; +import { TypeOrmModule } from '@nestjs/typeorm'; +import { ProjectEntity } from './entities'; + +@Module({ + providers: [], + exports: [], + controllers: [], + imports: [TypeOrmModule.forFeature([ProjectEntity])], +}) +export class ProjectEntityModule {} diff --git a/libs/common/src/modules/project/repositiories/index.ts b/libs/common/src/modules/project/repositiories/index.ts new file mode 100644 index 0000000..3e35c16 --- /dev/null +++ b/libs/common/src/modules/project/repositiories/index.ts @@ -0,0 +1 @@ +export * from './project.repository'; diff --git a/libs/common/src/modules/project/repositiories/project.repository.ts b/libs/common/src/modules/project/repositiories/project.repository.ts new file mode 100644 index 0000000..b4602e7 --- /dev/null +++ b/libs/common/src/modules/project/repositiories/project.repository.ts @@ -0,0 +1,10 @@ +import { DataSource, Repository } from 'typeorm'; +import { ProjectEntity } from '../entities'; +import { Injectable } from '@nestjs/common'; + +@Injectable() +export class ProjectRepository extends Repository { + constructor(private dataSource: DataSource) { + super(ProjectEntity, dataSource.createEntityManager()); + } +} From acbd5d53f13b4277292a2a7f8ad8235240df88ea Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Mon, 9 Dec 2024 11:20:40 +0400 Subject: [PATCH 02/10] name should be unique --- libs/common/src/modules/project/entities/project.entity.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/common/src/modules/project/entities/project.entity.ts b/libs/common/src/modules/project/entities/project.entity.ts index f614b50..7eb1956 100644 --- a/libs/common/src/modules/project/entities/project.entity.ts +++ b/libs/common/src/modules/project/entities/project.entity.ts @@ -1,8 +1,9 @@ -import { Entity, Column } from 'typeorm'; +import { Entity, Column, Unique } from 'typeorm'; import { AbstractEntity } from '../../abstract/entities/abstract.entity'; import { ProjectDto } from '../dtos'; @Entity({ name: 'project' }) +@Unique(['name']) export class ProjectEntity extends AbstractEntity { @Column({ type: 'uuid', From 54228c24eb62e922627e74d2f164a7621bc13556 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Mon, 9 Dec 2024 11:24:28 +0400 Subject: [PATCH 03/10] added description --- .../src/modules/project/dtos/project.dto.ts | 18 +++++++++--------- .../modules/project/entities/project.entity.ts | 3 +++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/libs/common/src/modules/project/dtos/project.dto.ts b/libs/common/src/modules/project/dtos/project.dto.ts index a5931af..ef08e55 100644 --- a/libs/common/src/modules/project/dtos/project.dto.ts +++ b/libs/common/src/modules/project/dtos/project.dto.ts @@ -1,15 +1,15 @@ -import { ApiProperty } from '@nestjs/swagger'; +import { IsNotEmpty, IsOptional, IsString } from 'class-validator'; export class ProjectDto { - @ApiProperty({ - example: 'd7a44e8a-32d5-4f39-ae2e-013f1245aead', - description: 'UUID of the project', - }) + @IsString() + @IsNotEmpty() uuid: string; - @ApiProperty({ - example: 'Project 1', - description: 'Name of the project', - }) + @IsString() + @IsNotEmpty() name: string; + + @IsString() + @IsOptional() + public description?: string; } diff --git a/libs/common/src/modules/project/entities/project.entity.ts b/libs/common/src/modules/project/entities/project.entity.ts index 7eb1956..ff324b2 100644 --- a/libs/common/src/modules/project/entities/project.entity.ts +++ b/libs/common/src/modules/project/entities/project.entity.ts @@ -17,6 +17,9 @@ export class ProjectEntity extends AbstractEntity { }) public name: string; + @Column({ length: 255, nullable: true }) + description: string; + constructor(partial: Partial) { super(); Object.assign(this, partial); From 7f739b88d8bbf012c12c1be6c989cb9dff355c13 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Mon, 9 Dec 2024 11:48:53 +0400 Subject: [PATCH 04/10] Project service to CRUD project entity --- .../src/util/buildTypeORMIncludeQuery.ts | 3 + src/project/services/index.ts | 1 + src/project/services/project.service.ts | 140 ++++++++++++++++++ 3 files changed, 144 insertions(+) create mode 100644 src/project/services/index.ts create mode 100644 src/project/services/project.service.ts diff --git a/libs/common/src/util/buildTypeORMIncludeQuery.ts b/libs/common/src/util/buildTypeORMIncludeQuery.ts index c2d401e..029bd67 100644 --- a/libs/common/src/util/buildTypeORMIncludeQuery.ts +++ b/libs/common/src/util/buildTypeORMIncludeQuery.ts @@ -16,6 +16,9 @@ const mappingInclude: { [key: string]: any } = { subspace: { subspace: true, }, + project: { + project: true, + }, }; export function buildTypeORMIncludeQuery( diff --git a/src/project/services/index.ts b/src/project/services/index.ts new file mode 100644 index 0000000..82e8c13 --- /dev/null +++ b/src/project/services/index.ts @@ -0,0 +1 @@ +export * from './project.service'; diff --git a/src/project/services/project.service.ts b/src/project/services/project.service.ts new file mode 100644 index 0000000..62070a2 --- /dev/null +++ b/src/project/services/project.service.ts @@ -0,0 +1,140 @@ +import { ProjectRepository } from '@app/common/modules/project/repositiories'; +import { HttpException, HttpStatus, Injectable } from '@nestjs/common'; +import { CreateProjectDto } from '../dto'; +import { BaseResponseDto } from '@app/common/dto/base.response.dto'; +import { SuccessResponseDto } from '@app/common/dto/success.response.dto'; +import { ProjectEntity } from '@app/common/modules/project/entities'; +import { + TypeORMCustomModel, + TypeORMCustomModelFindAllQuery, +} from '@app/common/models/typeOrmCustom.model'; +import { ProjectDto } from '@app/common/modules/project/dtos'; +import { PageResponse } from '@app/common/dto/pagination.response.dto'; + +@Injectable() +export class ProjectService { + constructor(private readonly projectRepository: ProjectRepository) {} + + async createProject( + createProjectDto: CreateProjectDto, + ): Promise { + const { name } = createProjectDto; + + try { + // Check if the project name already exists + const isNameExist = await this.validate(name); + if (isNameExist) { + throw new HttpException( + `Project with name ${name} already exists`, + HttpStatus.CONFLICT, + ); + } + + const newProject = this.projectRepository.create(createProjectDto); + const savedProject = await this.projectRepository.save(newProject); + + return new SuccessResponseDto({ + message: `Project with ID ${savedProject.uuid} successfully created`, + data: savedProject, + statusCode: HttpStatus.CREATED, + }); + } catch (error) { + if (error instanceof HttpException) { + throw error; + } + + throw new HttpException( + 'An error occurred while creating the project. Please try again later.', + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + } + + async deleteProject(uuid: string): Promise { + try { + // Find the project by UUID + const project = await this.findOne(uuid); + + if (!project) { + throw new HttpException( + `Project with ID ${uuid} not found`, + HttpStatus.NOT_FOUND, + ); + } + + // Delete the project + await this.projectRepository.delete({ uuid }); + + return new SuccessResponseDto({ + message: `Project with ID ${uuid} successfully deleted`, + statusCode: HttpStatus.OK, + }); + } catch (error) { + if (error instanceof HttpException) { + throw error; + } + + throw new HttpException( + `An error occurred while deleting the project ${uuid}`, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + } + + async listProjects( + pageable: Partial, + ): Promise { + try { + pageable.modelName = 'project'; + const customModel = TypeORMCustomModel(this.projectRepository); + + const { baseResponseDto, paginationResponseDto } = + await customModel.findAll(pageable); + return new PageResponse( + baseResponseDto, + paginationResponseDto, + ); + } catch (error) { + throw new HttpException(error.message, HttpStatus.INTERNAL_SERVER_ERROR); + } + } + + async getProject(uuid: string): Promise { + try { + // Find the project by UUID + const project = await this.findOne(uuid); + + if (!project) { + throw new HttpException( + `Project with ID ${uuid} not found`, + HttpStatus.NOT_FOUND, + ); + } + + return new SuccessResponseDto({ + message: `Project with ID ${uuid} retrieved successfully`, + data: project, + statusCode: HttpStatus.OK, + }); + } catch (error) { + if (error instanceof HttpException) { + throw error; + } + + throw new HttpException( + `An error occurred while retrieving the project with id ${uuid}`, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + } + + async findOne(uuid: string): Promise { + const project = await this.projectRepository.findOne({ where: { uuid } }); + return project; + } + + async validate(name: string): Promise { + const project = await this.projectRepository.findOne({ where: { name } }); + return !project; + } +} From 768ea7cad8b709cab5979d2ae0e68f9791b333d8 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Mon, 9 Dec 2024 12:26:53 +0400 Subject: [PATCH 05/10] add update project --- src/project/services/project.service.ts | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/project/services/project.service.ts b/src/project/services/project.service.ts index 62070a2..6ba7e0c 100644 --- a/src/project/services/project.service.ts +++ b/src/project/services/project.service.ts @@ -128,6 +128,52 @@ export class ProjectService { } } + async updateProject( + uuid: string, + updateProjectDto: CreateProjectDto, + ): Promise { + try { + // Find the project by UUID + const project = await this.findOne(uuid); + + if (!project) { + throw new HttpException( + `Project with ID ${uuid} not found`, + HttpStatus.NOT_FOUND, + ); + } + + if (updateProjectDto.name && updateProjectDto.name !== project.name) { + const isNameExist = await this.validate(updateProjectDto.name); + if (isNameExist) { + throw new HttpException( + `Project with name ${updateProjectDto.name} already exists`, + HttpStatus.CONFLICT, + ); + } + } + + // Update the project details + Object.assign(project, updateProjectDto); + const updatedProject = await this.projectRepository.save(project); + + return new SuccessResponseDto({ + message: `Project with ID ${uuid} successfully updated`, + data: updatedProject, + statusCode: HttpStatus.OK, + }); + } catch (error) { + if (error instanceof HttpException) { + throw error; + } + + throw new HttpException( + `An error occurred while updating the project with ID ${uuid}`, + HttpStatus.INTERNAL_SERVER_ERROR, + ); + } + } + async findOne(uuid: string): Promise { const project = await this.projectRepository.findOne({ where: { uuid } }); return project; From bab57ff5eb719934cc0c26fc5f8810a0f57b5866 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Mon, 9 Dec 2024 12:27:40 +0400 Subject: [PATCH 06/10] add route and api summary and details for project --- libs/common/src/constants/controller-route.ts | 81 ++++++++++++------- 1 file changed, 53 insertions(+), 28 deletions(-) diff --git a/libs/common/src/constants/controller-route.ts b/libs/common/src/constants/controller-route.ts index eeacd0f..9966637 100644 --- a/libs/common/src/constants/controller-route.ts +++ b/libs/common/src/constants/controller-route.ts @@ -1,4 +1,29 @@ export class ControllerRoute { + static PROJECT = class { + public static readonly ROUTE = 'projects'; + static ACTIONS = class { + public static readonly CREATE_PROJECT_SUMMARY = 'Create a new project'; + public static readonly CREATE_PROJECT_DESCRIPTION = + 'This endpoint allows you to create a new project by providing the required project details.'; + + public static readonly GET_PROJECT_SUMMARY = 'Retrieve project details'; + public static readonly GET_PROJECT_DESCRIPTION = + 'This endpoint retrieves the details of a project by its unique identifier (UUID).'; + + public static readonly UPDATE_PROJECT_SUMMARY = 'Update project details'; + public static readonly UPDATE_PROJECT_DESCRIPTION = + 'This endpoint updates the details of an existing project using its unique identifier (UUID).'; + + public static readonly LIST_PROJECTS_SUMMARY = 'List all projects'; + public static readonly LIST_PROJECTS_DESCRIPTION = + 'This endpoint retrieves a list of all existing projects, including their details.'; + + public static readonly DELETE_PROJECT_SUMMARY = 'Delete a project'; + public static readonly DELETE_PROJECT_DESCRIPTION = + 'This endpoint deletes an existing project by its unique identifier (UUID).'; + }; + }; + static REGION = class { public static readonly ROUTE = 'region'; static ACTIONS = class { @@ -649,40 +674,40 @@ export class ControllerRoute { public static readonly UPDATE_DEVICE_SCHEDULE_DESCRIPTION = 'This endpoint updates the schedule for a specific device.'; }; - }; - static DEVICE_STATUS_FIREBASE = class { - public static readonly ROUTE = 'device-status-firebase'; + static DEVICE_STATUS_FIREBASE = class { + public static readonly ROUTE = 'device-status-firebase'; - static ACTIONS = class { - public static readonly ADD_DEVICE_STATUS_SUMMARY = - 'Add device status to Firebase'; - public static readonly ADD_DEVICE_STATUS_DESCRIPTION = - 'This endpoint adds a device status in Firebase based on the provided device UUID.'; + static ACTIONS = class { + public static readonly ADD_DEVICE_STATUS_SUMMARY = + 'Add device status to Firebase'; + public static readonly ADD_DEVICE_STATUS_DESCRIPTION = + 'This endpoint adds a device status in Firebase based on the provided device UUID.'; - public static readonly GET_DEVICE_STATUS_SUMMARY = - 'Get device status from Firebase'; - public static readonly GET_DEVICE_STATUS_DESCRIPTION = - 'This endpoint retrieves a device status from Firebase using the device UUID.'; + public static readonly GET_DEVICE_STATUS_SUMMARY = + 'Get device status from Firebase'; + public static readonly GET_DEVICE_STATUS_DESCRIPTION = + 'This endpoint retrieves a device status from Firebase using the device UUID.'; + }; }; - }; - static DEVICE_MESSAGES_SUBSCRIPTION = class { - public static readonly ROUTE = 'device-messages/subscription'; + static DEVICE_MESSAGES_SUBSCRIPTION = class { + public static readonly ROUTE = 'device-messages/subscription'; - static ACTIONS = class { - public static readonly ADD_DEVICE_MESSAGES_SUBSCRIPTION_SUMMARY = - 'Add device messages subscription'; - public static readonly ADD_DEVICE_MESSAGES_SUBSCRIPTION_DESCRIPTION = - 'This endpoint adds a subscription for device messages.'; + static ACTIONS = class { + public static readonly ADD_DEVICE_MESSAGES_SUBSCRIPTION_SUMMARY = + 'Add device messages subscription'; + public static readonly ADD_DEVICE_MESSAGES_SUBSCRIPTION_DESCRIPTION = + 'This endpoint adds a subscription for device messages.'; - public static readonly GET_DEVICE_MESSAGES_SUBSCRIPTION_SUMMARY = - 'Get device messages subscription'; - public static readonly GET_DEVICE_MESSAGES_SUBSCRIPTION_DESCRIPTION = - 'This endpoint fetches a user’s subscription for a specific device.'; + public static readonly GET_DEVICE_MESSAGES_SUBSCRIPTION_SUMMARY = + 'Get device messages subscription'; + public static readonly GET_DEVICE_MESSAGES_SUBSCRIPTION_DESCRIPTION = + 'This endpoint fetches a user’s subscription for a specific device.'; - public static readonly DELETE_DEVICE_MESSAGES_SUBSCRIPTION_SUMMARY = - 'Delete device messages subscription'; - public static readonly DELETE_DEVICE_MESSAGES_SUBSCRIPTION_DESCRIPTION = - 'This endpoint deletes a user’s subscription for device messages.'; + public static readonly DELETE_DEVICE_MESSAGES_SUBSCRIPTION_SUMMARY = + 'Delete device messages subscription'; + public static readonly DELETE_DEVICE_MESSAGES_SUBSCRIPTION_DESCRIPTION = + 'This endpoint deletes a user’s subscription for device messages.'; + }; }; }; } From 459e97149828b14fce58a626e6fd4d0bd3c8dfbb Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Mon, 9 Dec 2024 12:44:57 +0400 Subject: [PATCH 07/10] added dto --- src/project/dto/create-project.dto.ts | 21 +++++++++++++++++++++ src/project/dto/get-project.param.ts | 11 +++++++++++ src/project/dto/index.ts | 2 ++ 3 files changed, 34 insertions(+) create mode 100644 src/project/dto/create-project.dto.ts create mode 100644 src/project/dto/get-project.param.ts create mode 100644 src/project/dto/index.ts diff --git a/src/project/dto/create-project.dto.ts b/src/project/dto/create-project.dto.ts new file mode 100644 index 0000000..9637856 --- /dev/null +++ b/src/project/dto/create-project.dto.ts @@ -0,0 +1,21 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsString, IsNotEmpty, IsOptional } from 'class-validator'; + +export class CreateProjectDto { + @ApiProperty({ + example: 'Project 1', + description: 'Name of the project', + }) + @IsString() + @IsNotEmpty() + name: string; + + @ApiProperty({ + example: 'Optional description of the project', + description: 'Description of the project', + required: false, + }) + @IsString() + @IsOptional() + description?: string; +} diff --git a/src/project/dto/get-project.param.ts b/src/project/dto/get-project.param.ts new file mode 100644 index 0000000..2ec5825 --- /dev/null +++ b/src/project/dto/get-project.param.ts @@ -0,0 +1,11 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsUUID } from 'class-validator'; + +export class GetProjectParam { + @ApiProperty({ + description: 'UUID of the Project', + example: 'd290f1ee-6c54-4b01-90e6-d701748f0851', + }) + @IsUUID() + projectUuid: string; +} diff --git a/src/project/dto/index.ts b/src/project/dto/index.ts new file mode 100644 index 0000000..568bd4f --- /dev/null +++ b/src/project/dto/index.ts @@ -0,0 +1,2 @@ +export * from './create-project.dto'; +export * from './get-project.param'; From bc2987295fe7b7c03b77f65863a432666a611389 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Mon, 9 Dec 2024 12:49:45 +0400 Subject: [PATCH 08/10] fixed typo in controller route --- libs/common/src/constants/controller-route.ts | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/libs/common/src/constants/controller-route.ts b/libs/common/src/constants/controller-route.ts index 9966637..2aff604 100644 --- a/libs/common/src/constants/controller-route.ts +++ b/libs/common/src/constants/controller-route.ts @@ -674,40 +674,40 @@ export class ControllerRoute { public static readonly UPDATE_DEVICE_SCHEDULE_DESCRIPTION = 'This endpoint updates the schedule for a specific device.'; }; - static DEVICE_STATUS_FIREBASE = class { - public static readonly ROUTE = 'device-status-firebase'; + }; + static DEVICE_STATUS_FIREBASE = class { + public static readonly ROUTE = 'device-status-firebase'; - static ACTIONS = class { - public static readonly ADD_DEVICE_STATUS_SUMMARY = - 'Add device status to Firebase'; - public static readonly ADD_DEVICE_STATUS_DESCRIPTION = - 'This endpoint adds a device status in Firebase based on the provided device UUID.'; + static ACTIONS = class { + public static readonly ADD_DEVICE_STATUS_SUMMARY = + 'Add device status to Firebase'; + public static readonly ADD_DEVICE_STATUS_DESCRIPTION = + 'This endpoint adds a device status in Firebase based on the provided device UUID.'; - public static readonly GET_DEVICE_STATUS_SUMMARY = - 'Get device status from Firebase'; - public static readonly GET_DEVICE_STATUS_DESCRIPTION = - 'This endpoint retrieves a device status from Firebase using the device UUID.'; - }; + public static readonly GET_DEVICE_STATUS_SUMMARY = + 'Get device status from Firebase'; + public static readonly GET_DEVICE_STATUS_DESCRIPTION = + 'This endpoint retrieves a device status from Firebase using the device UUID.'; }; - static DEVICE_MESSAGES_SUBSCRIPTION = class { - public static readonly ROUTE = 'device-messages/subscription'; + }; + static DEVICE_MESSAGES_SUBSCRIPTION = class { + public static readonly ROUTE = 'device-messages/subscription'; - static ACTIONS = class { - public static readonly ADD_DEVICE_MESSAGES_SUBSCRIPTION_SUMMARY = - 'Add device messages subscription'; - public static readonly ADD_DEVICE_MESSAGES_SUBSCRIPTION_DESCRIPTION = - 'This endpoint adds a subscription for device messages.'; + static ACTIONS = class { + public static readonly ADD_DEVICE_MESSAGES_SUBSCRIPTION_SUMMARY = + 'Add device messages subscription'; + public static readonly ADD_DEVICE_MESSAGES_SUBSCRIPTION_DESCRIPTION = + 'This endpoint adds a subscription for device messages.'; - public static readonly GET_DEVICE_MESSAGES_SUBSCRIPTION_SUMMARY = - 'Get device messages subscription'; - public static readonly GET_DEVICE_MESSAGES_SUBSCRIPTION_DESCRIPTION = - 'This endpoint fetches a user’s subscription for a specific device.'; + public static readonly GET_DEVICE_MESSAGES_SUBSCRIPTION_SUMMARY = + 'Get device messages subscription'; + public static readonly GET_DEVICE_MESSAGES_SUBSCRIPTION_DESCRIPTION = + 'This endpoint fetches a user’s subscription for a specific device.'; - public static readonly DELETE_DEVICE_MESSAGES_SUBSCRIPTION_SUMMARY = - 'Delete device messages subscription'; - public static readonly DELETE_DEVICE_MESSAGES_SUBSCRIPTION_DESCRIPTION = - 'This endpoint deletes a user’s subscription for device messages.'; - }; + public static readonly DELETE_DEVICE_MESSAGES_SUBSCRIPTION_SUMMARY = + 'Delete device messages subscription'; + public static readonly DELETE_DEVICE_MESSAGES_SUBSCRIPTION_DESCRIPTION = + 'This endpoint deletes a user’s subscription for device messages.'; }; }; } From 5b0494b41572a1c260ecac96e60fec20cd7c7016 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Mon, 9 Dec 2024 12:59:46 +0400 Subject: [PATCH 09/10] fixed uuid --- libs/common/src/modules/project/entities/project.entity.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/common/src/modules/project/entities/project.entity.ts b/libs/common/src/modules/project/entities/project.entity.ts index ff324b2..6c18b6c 100644 --- a/libs/common/src/modules/project/entities/project.entity.ts +++ b/libs/common/src/modules/project/entities/project.entity.ts @@ -10,7 +10,7 @@ export class ProjectEntity extends AbstractEntity { default: () => 'gen_random_uuid()', nullable: false, }) - public project_id: string; + public uuid: string; @Column({ nullable: false, From 1e5b61e3e05931fd0ef5c2389bd6d9b75f586ea0 Mon Sep 17 00:00:00 2001 From: hannathkadher Date: Mon, 9 Dec 2024 13:26:17 +0400 Subject: [PATCH 10/10] added project endpoints --- src/app.module.ts | 2 + src/project/controllers/index.ts | 1 + src/project/controllers/project.controller.ts | 89 +++++++++++++++++++ src/project/index.ts | 1 + src/project/project.module.ts | 12 +++ src/project/services/project.service.ts | 3 +- 6 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 src/project/controllers/index.ts create mode 100644 src/project/controllers/project.controller.ts create mode 100644 src/project/index.ts create mode 100644 src/project/project.module.ts diff --git a/src/app.module.ts b/src/app.module.ts index 609147c..bb5986b 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -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: [ { diff --git a/src/project/controllers/index.ts b/src/project/controllers/index.ts new file mode 100644 index 0000000..2b606fd --- /dev/null +++ b/src/project/controllers/index.ts @@ -0,0 +1 @@ +export * from './project.controller'; diff --git a/src/project/controllers/project.controller.ts b/src/project/controllers/project.controller.ts new file mode 100644 index 0000000..a39ced1 --- /dev/null +++ b/src/project/controllers/project.controller.ts @@ -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 { + 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 { + 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 { + 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 { + 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 { + return this.projectService.getProject(params.projectUuid); + } +} diff --git a/src/project/index.ts b/src/project/index.ts new file mode 100644 index 0000000..c3c63b7 --- /dev/null +++ b/src/project/index.ts @@ -0,0 +1 @@ +export * from './project.module'; diff --git a/src/project/project.module.ts b/src/project/project.module.ts new file mode 100644 index 0000000..9d82ba9 --- /dev/null +++ b/src/project/project.module.ts @@ -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 {} diff --git a/src/project/services/project.service.ts b/src/project/services/project.service.ts index 6ba7e0c..63ea252 100644 --- a/src/project/services/project.service.ts +++ b/src/project/services/project.service.ts @@ -180,7 +180,6 @@ export class ProjectService { } async validate(name: string): Promise { - const project = await this.projectRepository.findOne({ where: { name } }); - return !project; + return await this.projectRepository.exists({ where: { name } }); } }