mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-17 03:05:13 +00:00
refactor: remove occupancy module and related files
This commit is contained in:
@ -1 +0,0 @@
|
||||
export * from './occupancy.controller';
|
@ -1,71 +0,0 @@
|
||||
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
|
||||
import {
|
||||
ApiTags,
|
||||
ApiBearerAuth,
|
||||
ApiOperation,
|
||||
ApiParam,
|
||||
} from '@nestjs/swagger';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { OccupancyService } from '../services/occupancy.service';
|
||||
import {
|
||||
GetOccupancyDurationBySpaceDto,
|
||||
GetOccupancyHeatMapBySpaceDto,
|
||||
} from '../dto/get-occupancy.dto';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
import { SpaceParamsDto } from '../dto/occupancy-params.dto';
|
||||
|
||||
@ApiTags('Occupancy Module')
|
||||
@Controller({
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: ControllerRoute.Occupancy.ROUTE,
|
||||
})
|
||||
export class OccupancyController {
|
||||
constructor(private readonly occupancyService: OccupancyService) {}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('heat-map/space/:spaceUuid')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.Occupancy.ACTIONS.GET_OCCUPANCY_HEAT_MAP_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.Occupancy.ACTIONS.GET_OCCUPANCY_HEAT_MAP_DESCRIPTION,
|
||||
})
|
||||
@ApiParam({
|
||||
name: 'spaceUuid',
|
||||
description: 'UUID of the Space',
|
||||
required: true,
|
||||
})
|
||||
async getOccupancyHeatMapDataBySpace(
|
||||
@Param() params: SpaceParamsDto,
|
||||
@Query() query: GetOccupancyHeatMapBySpaceDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
return await this.occupancyService.getOccupancyHeatMapDataBySpace(
|
||||
params,
|
||||
query,
|
||||
);
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('duration/space/:spaceUuid')
|
||||
@ApiOperation({
|
||||
summary: ControllerRoute.Occupancy.ACTIONS.GET_OCCUPANCY_HEAT_MAP_SUMMARY,
|
||||
description:
|
||||
ControllerRoute.Occupancy.ACTIONS.GET_OCCUPANCY_HEAT_MAP_DESCRIPTION,
|
||||
})
|
||||
@ApiParam({
|
||||
name: 'spaceUuid',
|
||||
description: 'UUID of the Space',
|
||||
required: true,
|
||||
})
|
||||
async getOccupancyDurationDataBySpace(
|
||||
@Param() params: SpaceParamsDto,
|
||||
@Query() query: GetOccupancyDurationBySpaceDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
return await this.occupancyService.getOccupancyDurationDataBySpace(
|
||||
params,
|
||||
query,
|
||||
);
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||
import { Matches, IsNotEmpty } from 'class-validator';
|
||||
|
||||
export class GetOccupancyHeatMapBySpaceDto {
|
||||
@ApiPropertyOptional({
|
||||
description: 'Input year in YYYY format to filter the data',
|
||||
example: '2025',
|
||||
required: false,
|
||||
})
|
||||
@IsNotEmpty()
|
||||
@Matches(/^\d{4}$/, {
|
||||
message: 'Year must be in YYYY format',
|
||||
})
|
||||
year: string;
|
||||
}
|
||||
export class GetOccupancyDurationBySpaceDto {
|
||||
@ApiPropertyOptional({
|
||||
description: 'Month and year in format YYYY-MM',
|
||||
example: '2025-03',
|
||||
required: true,
|
||||
})
|
||||
@Matches(/^\d{4}-(0[1-9]|1[0-2])$/, {
|
||||
message: 'monthDate must be in YYYY-MM format',
|
||||
})
|
||||
@IsNotEmpty()
|
||||
monthDate: string;
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
import { IsNotEmpty, IsUUID } from 'class-validator';
|
||||
|
||||
export class SpaceParamsDto {
|
||||
@IsUUID('4', { message: 'Invalid UUID format' })
|
||||
@IsNotEmpty()
|
||||
spaceUuid: string;
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { ConfigModule } from '@nestjs/config';
|
||||
import { OccupancyController } from './controllers';
|
||||
import { SqlLoaderService } from '@app/common/helper/services/sql-loader.service';
|
||||
import { OccupancyService } from './services';
|
||||
@Module({
|
||||
imports: [ConfigModule],
|
||||
controllers: [OccupancyController],
|
||||
providers: [OccupancyService, SqlLoaderService],
|
||||
})
|
||||
export class OccupancyModule {}
|
@ -1 +0,0 @@
|
||||
export * from './occupancy.service';
|
@ -1,103 +0,0 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import {
|
||||
GetOccupancyDurationBySpaceDto,
|
||||
GetOccupancyHeatMapBySpaceDto,
|
||||
} from '../dto/get-occupancy.dto';
|
||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||
import { SpaceParamsDto } from '../dto/occupancy-params.dto';
|
||||
import { SqlLoaderService } from '@app/common/helper/services/sql-loader.service';
|
||||
import { DataSource } from 'typeorm';
|
||||
import { SQL_PROCEDURES_PATH } from '@app/common/constants/sql-query-path';
|
||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||
|
||||
@Injectable()
|
||||
export class OccupancyService {
|
||||
constructor(
|
||||
private readonly sqlLoader: SqlLoaderService,
|
||||
private readonly dataSource: DataSource,
|
||||
) {}
|
||||
|
||||
async getOccupancyDurationDataBySpace(
|
||||
params: SpaceParamsDto,
|
||||
query: GetOccupancyDurationBySpaceDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
const { monthDate } = query;
|
||||
const { spaceUuid } = params;
|
||||
|
||||
try {
|
||||
const data = await this.executeProcedure(
|
||||
'fact_daily_space_occupancy_duration',
|
||||
'procedure_select_daily_space_occupancy_duration',
|
||||
[spaceUuid, monthDate],
|
||||
);
|
||||
const formattedData = data.map((item) => ({
|
||||
...item,
|
||||
event_date: new Date(item.event_date).toLocaleDateString('en-CA'), // YYYY-MM-DD
|
||||
}));
|
||||
return this.buildResponse(
|
||||
`Occupancy duration data fetched successfully for ${spaceUuid} space`,
|
||||
formattedData,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch occupancy duration data', {
|
||||
error,
|
||||
spaceUuid,
|
||||
});
|
||||
throw new HttpException(
|
||||
error.response?.message || 'Failed to fetch occupancy duration data',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
async getOccupancyHeatMapDataBySpace(
|
||||
params: SpaceParamsDto,
|
||||
query: GetOccupancyHeatMapBySpaceDto,
|
||||
): Promise<BaseResponseDto> {
|
||||
const { year } = query;
|
||||
const { spaceUuid } = params;
|
||||
|
||||
try {
|
||||
const data = await this.executeProcedure(
|
||||
'fact_space_occupancy_count',
|
||||
'proceduce_select_fact_space_occupancy',
|
||||
[spaceUuid, year],
|
||||
);
|
||||
const formattedData = data.map((item) => ({
|
||||
...item,
|
||||
event_date: new Date(item.event_date).toLocaleDateString('en-CA'), // YYYY-MM-DD
|
||||
}));
|
||||
return this.buildResponse(
|
||||
`Occupancy heat map data fetched successfully for ${spaceUuid} space`,
|
||||
formattedData,
|
||||
);
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch occupancy heat map data', {
|
||||
error,
|
||||
spaceUuid,
|
||||
});
|
||||
throw new HttpException(
|
||||
error.response?.message || 'Failed to fetch occupancy heat map data',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private buildResponse(message: string, data: any[]) {
|
||||
return new SuccessResponseDto({
|
||||
message,
|
||||
data,
|
||||
statusCode: HttpStatus.OK,
|
||||
});
|
||||
}
|
||||
private async executeProcedure(
|
||||
procedureFolderName: string,
|
||||
procedureFileName: string,
|
||||
params: (string | number | null)[],
|
||||
): Promise<any[]> {
|
||||
const query = this.loadQuery(procedureFolderName, procedureFileName);
|
||||
return await this.dataSource.query(query, params);
|
||||
}
|
||||
private loadQuery(folderName: string, fileName: string): string {
|
||||
return this.sqlLoader.loadQuery(folderName, fileName, SQL_PROCEDURES_PATH);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user