create orphan community and space for project

This commit is contained in:
hannathkadher
2024-12-18 08:22:53 +04:00
parent 885d43d834
commit a5ab883957
8 changed files with 88 additions and 6 deletions

View File

@ -10,10 +10,15 @@ import {
} from '@app/common/models/typeOrmCustom.model';
import { ProjectDto } from '@app/common/modules/project/dtos';
import { PageResponse } from '@app/common/dto/pagination.response.dto';
import { CommandBus } from '@nestjs/cqrs';
import { CreateOrphanSpaceCommand } from '../command/create-orphan-space-command';
@Injectable()
export class ProjectService {
constructor(private readonly projectRepository: ProjectRepository) {}
constructor(
private readonly projectRepository: ProjectRepository,
private commandBus: CommandBus,
) {}
async createProject(
createProjectDto: CreateProjectDto,
@ -33,6 +38,8 @@ export class ProjectService {
const newProject = this.projectRepository.create(createProjectDto);
const savedProject = await this.projectRepository.save(newProject);
await this.commandBus.execute(new CreateOrphanSpaceCommand(savedProject));
return new SuccessResponseDto({
message: `Project with ID ${savedProject.uuid} successfully created`,
data: savedProject,
@ -44,7 +51,7 @@ export class ProjectService {
}
throw new HttpException(
'An error occurred while creating the project. Please try again later.',
`An error occurred while creating the project. Please try again later. ${error}`,
HttpStatus.INTERNAL_SERVER_ERROR,
);
}