mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-11-26 12:54:54 +00:00
list space-model
This commit is contained in:
@ -1,5 +1,13 @@
|
||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||
import { Body, Controller, Param, Post, UseGuards } from '@nestjs/common';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Get,
|
||||
Param,
|
||||
Post,
|
||||
Query,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||
import { SpaceModelService } from '../services';
|
||||
import { CreateSpaceModelDto } from '../dtos';
|
||||
@ -7,6 +15,7 @@ import { ProjectParam } from 'src/community/dtos';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
||||
import { Permissions } from 'src/decorators/permissions.decorator';
|
||||
import { PaginationRequestGetListDto } from '@app/common/dto/pagination.request.dto';
|
||||
|
||||
@ApiTags('Space Model Module')
|
||||
@Controller({
|
||||
@ -34,4 +43,20 @@ export class SpaceModelController {
|
||||
projectParam,
|
||||
);
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(PermissionsGuard)
|
||||
@Permissions('SPACE_MODEL_VIEW')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.SPACE_MODEL.ACTIONS.LIST_SPACE_MODEL_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.SPACE_MODEL.ACTIONS.LIST_SPACE_MODEL_DESCRIPTION,
|
||||
})
|
||||
@Get()
|
||||
async listSpaceModel(
|
||||
@Param() projectParam: ProjectParam,
|
||||
@Query() query: PaginationRequestGetListDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
return await this.spaceModelService.list(projectParam, query);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,6 +7,12 @@ import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
import { SubSpaceModelService } from './subspace/subspace-model.service';
|
||||
import { SpaceProductModelService } from './space-product-model.service';
|
||||
import { DataSource } from 'typeorm';
|
||||
import {
|
||||
TypeORMCustomModel,
|
||||
TypeORMCustomModelFindAllQuery,
|
||||
} from '@app/common/models/typeOrmCustom.model';
|
||||
import { PageResponse } from '@app/common/dto/pagination.response.dto';
|
||||
import { SpaceModelDto } from '@app/common/modules/space-model/dtos';
|
||||
|
||||
@Injectable()
|
||||
export class SpaceModelService {
|
||||
@ -87,6 +93,38 @@ export class SpaceModelService {
|
||||
}
|
||||
}
|
||||
|
||||
async list(
|
||||
param: ProjectParam,
|
||||
pageable: Partial<TypeORMCustomModelFindAllQuery>,
|
||||
) {
|
||||
await this.validateProject(param.projectUuid);
|
||||
|
||||
try {
|
||||
pageable.modelName = 'space-model';
|
||||
pageable.where = {
|
||||
project: { uuid: param.projectUuid },
|
||||
};
|
||||
pageable.include =
|
||||
'subspaceModels,spaceProductModels,subspaceModels.productModels,subspaceModels.productModels.itemModels,spaceProductModels.items';
|
||||
|
||||
const customModel = TypeORMCustomModel(this.spaceModelRepository);
|
||||
|
||||
const { baseResponseDto, paginationResponseDto } =
|
||||
await customModel.findAll(pageable);
|
||||
|
||||
return new PageResponse<SpaceModelDto>(
|
||||
baseResponseDto,
|
||||
paginationResponseDto,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message ||
|
||||
'An error occurred while fetching space models in project.',
|
||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async validateProject(projectUuid: string) {
|
||||
const project = await this.projectRepository.findOne({
|
||||
where: {
|
||||
|
||||
Reference in New Issue
Block a user