mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
added formatting for list space model
This commit is contained in:
@ -128,31 +128,36 @@ export class SpaceModelService {
|
||||
disabled: false,
|
||||
};
|
||||
pageable.include =
|
||||
'subspaceModels,tags,subspaceModels.tags,tags.product,subspaceModels.tags.product';
|
||||
'subspaceModels.productAllocations,subspaceModelProductAllocations.tags,subspaceModels, productAllocations, productAllocations.tags';
|
||||
|
||||
const queryBuilder = await this.spaceModelRepository
|
||||
const queryBuilder = this.spaceModelRepository
|
||||
.createQueryBuilder('spaceModel')
|
||||
.leftJoinAndSelect(
|
||||
'spaceModel.subspaceModels',
|
||||
'subspaceModels',
|
||||
'subspaceModels.disabled = :subspaceDisabled',
|
||||
{ subspaceDisabled: false },
|
||||
'subspaceModels.disabled = false',
|
||||
)
|
||||
.leftJoinAndSelect(
|
||||
'spaceModel.tags',
|
||||
'tags',
|
||||
'tags.disabled = :tagsDisabled',
|
||||
{ tagsDisabled: false },
|
||||
'subspaceModels.productAllocations',
|
||||
'subspaceModelProductAllocations',
|
||||
)
|
||||
.leftJoinAndSelect('tags.product', 'spaceTagproduct')
|
||||
// Ensure correct aliasing for the ManyToMany relation
|
||||
.leftJoinAndSelect(
|
||||
'subspaceModels.tags',
|
||||
'subspaceModelProductAllocations.tags',
|
||||
'subspaceModelTags',
|
||||
'subspaceModelTags.disabled = :subspaceModelTagsDisabled',
|
||||
{ subspaceModelTagsDisabled: false },
|
||||
)
|
||||
.leftJoinAndSelect('subspaceModelTags.product', 'subspaceTagproduct')
|
||||
.where('spaceModel.disabled = :disabled', { disabled: false })
|
||||
.leftJoinAndSelect(
|
||||
'subspaceModelTags.product',
|
||||
'subspaceModelTagProduct',
|
||||
)
|
||||
.leftJoinAndSelect(
|
||||
'spaceModel.productAllocations',
|
||||
'productAllocations',
|
||||
)
|
||||
.leftJoinAndSelect('productAllocations.product', 'allocatedProduct')
|
||||
.leftJoinAndSelect('productAllocations.tags', 'productTags')
|
||||
.leftJoinAndSelect('productTags.product', 'productTagProduct')
|
||||
.where('spaceModel.disabled = false')
|
||||
.andWhere('spaceModel.project = :projectUuid', {
|
||||
projectUuid: param.projectUuid,
|
||||
});
|
||||
@ -168,10 +173,87 @@ export class SpaceModelService {
|
||||
queryBuilder,
|
||||
);
|
||||
|
||||
return new PageResponse<SpaceModelDto>(
|
||||
baseResponseDto,
|
||||
paginationResponseDto,
|
||||
// Ensure baseResponseDto is an array
|
||||
const spaceModelsArray = Array.isArray(baseResponseDto.data)
|
||||
? baseResponseDto.data
|
||||
: [baseResponseDto.data];
|
||||
|
||||
// Log to verify correct data retrieval
|
||||
console.log(
|
||||
'SpaceModelsArray:',
|
||||
JSON.stringify(spaceModelsArray, null, 2),
|
||||
);
|
||||
|
||||
// Format response
|
||||
const formattedData = spaceModelsArray.map((spaceModel) => ({
|
||||
uuid: spaceModel.uuid,
|
||||
createdAt: spaceModel.createdAt,
|
||||
updatedAt: spaceModel.updatedAt,
|
||||
modelName: spaceModel.modelName,
|
||||
disabled: spaceModel.disabled,
|
||||
subspaceModels: (spaceModel.subspaceModels ?? []).map((subspace) => ({
|
||||
uuid: subspace.uuid,
|
||||
createdAt: subspace.createdAt,
|
||||
updatedAt: subspace.updatedAt,
|
||||
subspaceName: subspace.subspaceName,
|
||||
disabled: subspace.disabled,
|
||||
tags: (subspace.productAllocations ?? [])
|
||||
.flatMap((allocation) => allocation.tags ?? [])
|
||||
.map((tag) => ({
|
||||
uuid: tag.uuid,
|
||||
createdAt: tag.createdAt,
|
||||
updatedAt: tag.updatedAt,
|
||||
tag: tag.tag,
|
||||
disabled: tag.disabled,
|
||||
product: tag.product
|
||||
? {
|
||||
uuid: tag.product.uuid,
|
||||
createdAt: tag.product.createdAt,
|
||||
updatedAt: tag.product.updatedAt,
|
||||
catName: tag.product.catName,
|
||||
prodId: tag.product.prodId,
|
||||
name: tag.product.name,
|
||||
prodType: tag.product.prodType,
|
||||
}
|
||||
: null,
|
||||
})),
|
||||
})),
|
||||
tags: (spaceModel.productAllocations ?? [])
|
||||
.flatMap((allocation) => allocation.tags ?? [])
|
||||
.map((tag) => ({
|
||||
uuid: tag.uuid,
|
||||
createdAt: tag.createdAt,
|
||||
updatedAt: tag.updatedAt,
|
||||
tag: tag.tag,
|
||||
disabled: tag.disabled,
|
||||
product: tag.product
|
||||
? {
|
||||
uuid: tag.product.uuid,
|
||||
createdAt: tag.product.createdAt,
|
||||
updatedAt: tag.product.updatedAt,
|
||||
catName: tag.product.catName,
|
||||
prodId: tag.product.prodId,
|
||||
name: tag.product.name,
|
||||
prodType: tag.product.prodType,
|
||||
}
|
||||
: null,
|
||||
})),
|
||||
}));
|
||||
|
||||
// Log to verify formatted response
|
||||
console.log('FormattedData:', JSON.stringify(formattedData, null, 2));
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
data: formattedData,
|
||||
message: 'Success get list spaceModel',
|
||||
page: paginationResponseDto.page,
|
||||
size: paginationResponseDto.size,
|
||||
totalItem: paginationResponseDto.totalItem,
|
||||
totalPage: paginationResponseDto.totalPage,
|
||||
hasNext: paginationResponseDto.hasNext,
|
||||
hasPrevious: paginationResponseDto.hasPrevious,
|
||||
};
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
`Error fetching paginated list: ${error.message}`,
|
||||
|
Reference in New Issue
Block a user