mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 08:34:55 +00:00
add logs
This commit is contained in:
@ -50,63 +50,100 @@ export class SpaceModelService {
|
||||
createSpaceModelDto: CreateSpaceModelDto,
|
||||
params: ProjectParam,
|
||||
): Promise<BaseResponseDto> {
|
||||
console.log('[START] createSpaceModel', { createSpaceModelDto, params });
|
||||
|
||||
const { modelName, subspaceModels, tags } = createSpaceModelDto;
|
||||
const queryRunner = this.dataSource.createQueryRunner();
|
||||
|
||||
await queryRunner.connect();
|
||||
await queryRunner.startTransaction();
|
||||
|
||||
try {
|
||||
console.log('[STEP 1] Validating Project:', params.projectUuid);
|
||||
const project = await this.projectService.findOne(params.projectUuid);
|
||||
|
||||
if (!project) {
|
||||
console.error('[ERROR] Project not found', params.projectUuid);
|
||||
throw new HttpException('Project not found', HttpStatus.NOT_FOUND);
|
||||
}
|
||||
console.log('[STEP 1 SUCCESS] Project found:', project);
|
||||
|
||||
console.log('[STEP 2] Validating model name:', modelName);
|
||||
await this.validateNameUsingQueryRunner(
|
||||
modelName,
|
||||
params.projectUuid,
|
||||
queryRunner,
|
||||
);
|
||||
console.log('[STEP 2 SUCCESS] Model name validated');
|
||||
|
||||
console.log('[STEP 3] Creating SpaceModel entity');
|
||||
const spaceModel = this.spaceModelRepository.create({
|
||||
modelName,
|
||||
project,
|
||||
});
|
||||
console.log('[STEP 3 SUCCESS] SpaceModel entity created:', spaceModel);
|
||||
|
||||
console.log('[STEP 4] Saving SpaceModel');
|
||||
const savedSpaceModel = await queryRunner.manager.save(spaceModel);
|
||||
console.log('[STEP 4 SUCCESS] SpaceModel saved:', savedSpaceModel);
|
||||
|
||||
console.log('[STEP 5] Validating unique tags');
|
||||
this.validateUniqueTags(
|
||||
tags,
|
||||
this.subSpaceModelService.extractSubspaceTags(subspaceModels),
|
||||
);
|
||||
console.log('[STEP 5 SUCCESS] Unique tags validated');
|
||||
|
||||
if (subspaceModels?.length) {
|
||||
console.log('[STEP 6] Creating Subspace Models');
|
||||
savedSpaceModel.subspaceModels =
|
||||
await this.subSpaceModelService.createModels(
|
||||
savedSpaceModel,
|
||||
subspaceModels,
|
||||
queryRunner,
|
||||
);
|
||||
console.log(
|
||||
'[STEP 6 SUCCESS] Subspace Models created:',
|
||||
savedSpaceModel.subspaceModels,
|
||||
);
|
||||
}
|
||||
|
||||
if (tags?.length) {
|
||||
console.log('[STEP 7] Processing tags');
|
||||
const processedTags = await this.tagService.processTags(
|
||||
tags,
|
||||
params.projectUuid,
|
||||
);
|
||||
console.log('[STEP 7 SUCCESS] Tags processed:', processedTags);
|
||||
|
||||
console.log('[STEP 8] Creating product allocations');
|
||||
await this.createProductAllocations(spaceModel, processedTags);
|
||||
console.log('[STEP 8 SUCCESS] Product allocations created');
|
||||
}
|
||||
|
||||
console.log('[STEP 9] Committing transaction');
|
||||
await queryRunner.commitTransaction();
|
||||
console.log('[STEP 9 SUCCESS] Transaction committed');
|
||||
|
||||
console.log(
|
||||
'[COMPLETE] Successfully created space model',
|
||||
savedSpaceModel,
|
||||
);
|
||||
return new SuccessResponseDto({
|
||||
message: `Successfully created new space model with uuid ${savedSpaceModel.uuid}`,
|
||||
data: savedSpaceModel,
|
||||
statusCode: HttpStatus.CREATED,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('[ERROR] Exception occurred:', error);
|
||||
|
||||
await queryRunner.rollbackTransaction();
|
||||
console.log('[ROLLBACK] Transaction rolled back due to error');
|
||||
|
||||
const errorMessage =
|
||||
error instanceof HttpException
|
||||
? error.message
|
||||
: `An unexpected error occurred ${error.message}`;
|
||||
: `An unexpected error occurred: ${error.message}`;
|
||||
const statusCode =
|
||||
error instanceof HttpException
|
||||
? error.getStatus()
|
||||
@ -114,6 +151,7 @@ export class SpaceModelService {
|
||||
|
||||
throw new HttpException(errorMessage, statusCode);
|
||||
} finally {
|
||||
console.log('[CLEANUP] Releasing query runner');
|
||||
await queryRunner.release();
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,12 +36,18 @@ export class SubSpaceModelService {
|
||||
dtos: CreateSubspaceModelDto[],
|
||||
queryRunner: QueryRunner,
|
||||
) {
|
||||
console.log('[START] createModels - Creating Subspace Models', { dtos });
|
||||
|
||||
this.validateNamesInDTO(dtos.map((dto) => dto.subspaceName));
|
||||
console.log('[STEP 1 SUCCESS] Validated Subspace Names');
|
||||
|
||||
const subspaceEntities: SubspaceModelEntity[] = [];
|
||||
|
||||
for (const dto of dtos) {
|
||||
// Create Subspace Model entity
|
||||
console.log('[STEP 2] Creating Subspace Model Entity', {
|
||||
subspaceName: dto.subspaceName,
|
||||
});
|
||||
|
||||
const subspaceModel = queryRunner.manager.create(
|
||||
this.subspaceModelRepository.target,
|
||||
{
|
||||
@ -49,22 +55,36 @@ export class SubSpaceModelService {
|
||||
spaceModel,
|
||||
},
|
||||
);
|
||||
console.log(
|
||||
'[STEP 2 SUCCESS] Subspace Model Entity Created:',
|
||||
subspaceModel,
|
||||
);
|
||||
|
||||
subspaceEntities.push(subspaceModel);
|
||||
}
|
||||
|
||||
console.log('[STEP 3] Saving Subspace Models:', subspaceEntities);
|
||||
|
||||
const savedSubspaces = await queryRunner.manager.save(subspaceEntities);
|
||||
console.log('[STEP 3 SUCCESS] Subspace Models Saved:', savedSubspaces);
|
||||
|
||||
for (const [index, dto] of dtos.entries()) {
|
||||
const subspaceModel = savedSubspaces[index];
|
||||
console.log('[STEP 4] Processing Tags for Subspace Model', {
|
||||
subspaceName: dto.subspaceName,
|
||||
});
|
||||
|
||||
const processedTags = await this.tagService.processTags(
|
||||
dto.tags,
|
||||
spaceModel.project.uuid,
|
||||
);
|
||||
console.log('[STEP 4 SUCCESS] Tags Processed:', processedTags);
|
||||
|
||||
await this.createSubspaceProductAllocations(subspaceModel, processedTags);
|
||||
console.log('[STEP 5 SUCCESS] Subspace Product Allocations Created');
|
||||
}
|
||||
console.log('[COMPLETE] Successfully Created Subspace Models');
|
||||
|
||||
return savedSubspaces;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user