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