mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:54:54 +00:00
aadded product item to space
This commit is contained in:
@ -63,7 +63,7 @@ export class SpaceService {
|
||||
: null;
|
||||
|
||||
try {
|
||||
const newSpace = this.spaceRepository.create({
|
||||
const newSpace = queryRunner.manager.create(SpaceEntity, {
|
||||
...addSpaceDto,
|
||||
spaceModel,
|
||||
parent: parentUuid ? parent : null,
|
||||
@ -80,13 +80,13 @@ export class SpaceService {
|
||||
);
|
||||
}
|
||||
|
||||
if (subspaces) {
|
||||
if (subspaces?.length) {
|
||||
await this.subSpaceService.createSubspacesFromNames(
|
||||
subspaces,
|
||||
newSpace,
|
||||
queryRunner,
|
||||
);
|
||||
} else {
|
||||
} else if (spaceModel && spaceModel.subspaceModels.length) {
|
||||
await this.subSpaceService.createSubSpaceFromModel(
|
||||
spaceModel,
|
||||
newSpace,
|
||||
@ -98,6 +98,13 @@ export class SpaceService {
|
||||
await this.spaceProductService.assignProductsToSpace(
|
||||
newSpace,
|
||||
products,
|
||||
queryRunner,
|
||||
);
|
||||
} else if (spaceModel && spaceModel.spaceProductModels.length) {
|
||||
await this.spaceProductService.createProductItemFromModel(
|
||||
spaceModel,
|
||||
newSpace,
|
||||
queryRunner,
|
||||
);
|
||||
}
|
||||
await queryRunner.commitTransaction();
|
||||
@ -216,7 +223,12 @@ export class SpaceService {
|
||||
updateSpaceDto: UpdateSpaceDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
const { communityUuid, spaceUuid, projectUuid } = params;
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
|
||||
try {
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
|
||||
const space =
|
||||
await this.validationService.validateSpaceWithinCommunityAndProject(
|
||||
communityUuid,
|
||||
@ -234,14 +246,16 @@ export class SpaceService {
|
||||
Object.assign(space, updateSpaceDto, { parent });
|
||||
|
||||
// Save the updated space
|
||||
const updatedSpace = await this.spaceRepository.save(space);
|
||||
const updatedSpace = await queryRunner.manager.save(space);
|
||||
|
||||
if (products && products.length > 0) {
|
||||
await this.spaceProductService.assignProductsToSpace(
|
||||
updatedSpace,
|
||||
products,
|
||||
queryRunner,
|
||||
);
|
||||
}
|
||||
await queryRunner.commitTransaction();
|
||||
|
||||
return new SuccessResponseDto({
|
||||
message: `Space with ID ${spaceUuid} successfully updated`,
|
||||
@ -249,6 +263,8 @@ export class SpaceService {
|
||||
statusCode: HttpStatus.OK,
|
||||
});
|
||||
} catch (error) {
|
||||
await queryRunner.rollbackTransaction();
|
||||
|
||||
if (error instanceof HttpException) {
|
||||
throw error;
|
||||
}
|
||||
@ -256,6 +272,8 @@ export class SpaceService {
|
||||
'An error occurred while updating the space',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
} finally {
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -348,13 +366,6 @@ export class SpaceService {
|
||||
return rootSpaces;
|
||||
}
|
||||
|
||||
private throwNotFound(entity: string, uuid: string) {
|
||||
throw new HttpException(
|
||||
`${entity} with ID ${uuid} not found`,
|
||||
HttpStatus.NOT_FOUND,
|
||||
);
|
||||
}
|
||||
|
||||
private validateSpaceCreation(
|
||||
spaceModelUuid?: string,
|
||||
products?: ProductAssignmentDto[],
|
||||
@ -362,7 +373,7 @@ export class SpaceService {
|
||||
) {
|
||||
if (spaceModelUuid && (products?.length || subSpaces?.length)) {
|
||||
throw new HttpException(
|
||||
'Space model cannot be assigned with products or subspaces.',
|
||||
'For space creation choose either space model or products and subspace',
|
||||
HttpStatus.CONFLICT,
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user