mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 10:24:53 +00:00
add update project
This commit is contained in:
@ -128,6 +128,52 @@ export class ProjectService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateProject(
|
||||||
|
uuid: string,
|
||||||
|
updateProjectDto: CreateProjectDto,
|
||||||
|
): Promise<BaseResponseDto> {
|
||||||
|
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<ProjectEntity> {
|
async findOne(uuid: string): Promise<ProjectEntity> {
|
||||||
const project = await this.projectRepository.findOne({ where: { uuid } });
|
const project = await this.projectRepository.findOne({ where: { uuid } });
|
||||||
return project;
|
return project;
|
||||||
|
|||||||
Reference in New Issue
Block a user