mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-15 18:27:05 +00:00
added enums to replace constants
This commit is contained in:
@ -1,11 +1,12 @@
|
||||
import { registerAs } from '@nestjs/config';
|
||||
import { BooleanValues } from '../constants/boolean-values.enum';
|
||||
|
||||
export default registerAs(
|
||||
'email-config',
|
||||
(): Record<string, any> => ({
|
||||
SMTP_HOST: process.env.SMTP_HOST,
|
||||
SMTP_PORT: parseInt(process.env.SMTP_PORT),
|
||||
SMTP_SECURE: process.env.SMTP_SECURE === 'true',
|
||||
SMTP_SECURE: process.env.SMTP_SECURE === BooleanValues.TRUE,
|
||||
SMTP_USER: process.env.SMTP_USER,
|
||||
SMTP_SENDER: process.env.SMTP_SENDER,
|
||||
SMTP_PASSWORD: process.env.SMTP_PASSWORD,
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { registerAs } from '@nestjs/config';
|
||||
import { BooleanValues } from '../constants/boolean-values.enum';
|
||||
|
||||
export default registerAs(
|
||||
'tuya-config',
|
||||
@ -7,6 +8,6 @@ export default registerAs(
|
||||
TUYA_ACCESS_KEY: process.env.TUYA_ACCESS_KEY,
|
||||
TUYA_EU_URL: process.env.TUYA_EU_URL,
|
||||
TRUN_ON_TUYA_SOCKET:
|
||||
process.env.TRUN_ON_TUYA_SOCKET === 'true' ? true : false,
|
||||
process.env.TRUN_ON_TUYA_SOCKET === BooleanValues.TRUE ? true : false,
|
||||
}),
|
||||
);
|
||||
|
9
libs/common/src/constants/automation.enum.ts
Normal file
9
libs/common/src/constants/automation.enum.ts
Normal file
@ -0,0 +1,9 @@
|
||||
// automation.enum.ts
|
||||
export enum ActionExecutorEnum {
|
||||
DEVICE_ISSUE = 'device_issue',
|
||||
DELAY = 'delay',
|
||||
}
|
||||
|
||||
export enum EntityTypeEnum {
|
||||
DEVICE_REPORT = 'device_report',
|
||||
}
|
4
libs/common/src/constants/battery-status.enum.ts
Normal file
4
libs/common/src/constants/battery-status.enum.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum BatteryStatus {
|
||||
RESIDUAL_ELECTRICITY = 'residual_electricity',
|
||||
BATTERY_PERCENTAGE = 'battery_percentage',
|
||||
}
|
4
libs/common/src/constants/boolean-values.enum.ts
Normal file
4
libs/common/src/constants/boolean-values.enum.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum BooleanValues {
|
||||
TRUE = 'true',
|
||||
FALSE = 'false',
|
||||
}
|
14
libs/common/src/constants/days.enum.ts
Normal file
14
libs/common/src/constants/days.enum.ts
Normal file
@ -0,0 +1,14 @@
|
||||
export enum DaysEnum {
|
||||
SUN = 'Sun',
|
||||
MON = 'Mon',
|
||||
TUE = 'Tue',
|
||||
WED = 'Wed',
|
||||
THU = 'Thu',
|
||||
FRI = 'Fri',
|
||||
SAT = 'Sat',
|
||||
}
|
||||
|
||||
export enum EnableDisableStatusEnum {
|
||||
DISABLED = '0',
|
||||
ENABLED = '1',
|
||||
}
|
4
libs/common/src/constants/device-status.enum.ts
Normal file
4
libs/common/src/constants/device-status.enum.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum DeviceStatuses {
|
||||
REJECTED = 'rejected',
|
||||
FULLFILLED = 'fulfilled',
|
||||
}
|
3
libs/common/src/constants/error-codes.enum.ts
Normal file
3
libs/common/src/constants/error-codes.enum.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export enum CommonErrorCodes {
|
||||
DUPLICATE_ENTITY = '23505',
|
||||
}
|
99
libs/common/src/constants/hours-minutes.enum.ts
Normal file
99
libs/common/src/constants/hours-minutes.enum.ts
Normal file
@ -0,0 +1,99 @@
|
||||
export enum CommonHours {
|
||||
ONE = '01:00',
|
||||
ONE_THIRTY = '01:30',
|
||||
TWO = '02:00',
|
||||
TWO_THIRTY = '02:30',
|
||||
THREE = '03:00',
|
||||
THREE_THIRTY = '03:30',
|
||||
FOUR = '04:00',
|
||||
FOUR_THIRTY = '04:30',
|
||||
FIVE = '05:00',
|
||||
FIVE_THIRTY = '05:30',
|
||||
SIX = '06:00',
|
||||
SIX_THIRTY = '06:30',
|
||||
SEVEN = '07:00',
|
||||
SEVEN_THIRTY = '07:30',
|
||||
EIGHT = '08:00',
|
||||
EIGHT_THIRTY = '08:30',
|
||||
NINE = '09:00',
|
||||
NINE_THIRTY = '09:30',
|
||||
TEN = '10:00',
|
||||
TEN_THIRTY = '10:30',
|
||||
ELEVEN = '11:00',
|
||||
ELEVEN_THIRTY = '11:30',
|
||||
TWELVE = '12:00',
|
||||
TWELVE_THIRTY = '12:30',
|
||||
THIRTEEN = '13:00',
|
||||
THIRTEEN_THIRTY = '13:30',
|
||||
FOURTEEN = '14:00',
|
||||
FOURTEEN_THIRTY = '14:30',
|
||||
FIFTEEN = '15:00',
|
||||
FIFTEEN_THIRTY = '15:30',
|
||||
SIXTEEN = '16:00',
|
||||
SIXTEEN_THIRTY = '16:30',
|
||||
SEVENTEEN = '17:00',
|
||||
SEVENTEEN_THIRTY = '17:30',
|
||||
EIGHTEEN = '18:00',
|
||||
EIGHTEEN_THIRTY = '18:30',
|
||||
NINETEEN = '19:00',
|
||||
NINETEEN_THIRTY = '19:30',
|
||||
TWENTY = '20:00',
|
||||
TWENTY_THIRTY = '20:30',
|
||||
TWENTY_ONE = '21:00',
|
||||
TWENTY_ONE_THIRTY = '21:30',
|
||||
TWENTY_TWO = '22:00',
|
||||
TWENTY_TWO_THIRTY = '22:30',
|
||||
TWENTY_THREE = '23:00',
|
||||
TWENTY_THREE_THIRTY = '23:30',
|
||||
TWENTY_FOUR = '24:00',
|
||||
}
|
||||
|
||||
export enum CommonHourMinutes {
|
||||
ONE = 60,
|
||||
ONE_THIRTY = 90,
|
||||
TWO = 120,
|
||||
TWO_THIRTY = 150,
|
||||
THREE = 180,
|
||||
THREE_THIRTY = 210,
|
||||
FOUR = 240,
|
||||
FOUR_THIRTY = 270,
|
||||
FIVE = 300,
|
||||
FIVE_THIRTY = 330,
|
||||
SIX = 360,
|
||||
SIX_THIRTY = 390,
|
||||
SEVEN = 420,
|
||||
SEVEN_THIRTY = 450,
|
||||
EIGHT = 480,
|
||||
EIGHT_THIRTY = 510,
|
||||
NINE = 540,
|
||||
NINE_THIRTY = 570,
|
||||
TEN = 600,
|
||||
TEN_THIRTY = 630,
|
||||
ELEVEN = 660,
|
||||
ELEVEN_THIRTY = 690,
|
||||
TWELVE = 720,
|
||||
TWELVE_THIRTY = 750,
|
||||
THIRTEEN = 780,
|
||||
THIRTEEN_THIRTY = 810,
|
||||
FOURTEEN = 840,
|
||||
FOURTEEN_THIRTY = 870,
|
||||
FIFTEEN = 900,
|
||||
FIFTEEN_THIRTY = 930,
|
||||
SIXTEEN = 960,
|
||||
SIXTEEN_THIRTY = 990,
|
||||
SEVENTEEN = 1020,
|
||||
SEVENTEEN_THIRTY = 1050,
|
||||
EIGHTEEN = 1080,
|
||||
EIGHTEEN_THIRTY = 1110,
|
||||
NINETEEN = 1140,
|
||||
NINETEEN_THIRTY = 1170,
|
||||
TWENTY = 1200,
|
||||
TWENTY_THIRTY = 1230,
|
||||
TWENTY_ONE = 1260,
|
||||
TWENTY_ONE_THIRTY = 1290,
|
||||
TWENTY_TWO = 1320,
|
||||
TWENTY_TWO_THIRTY = 1350,
|
||||
TWENTY_THREE = 1380,
|
||||
TWENTY_THREE_THIRTY = 1410,
|
||||
TWENTY_FOUR = 1440,
|
||||
}
|
4
libs/common/src/constants/password-type.enum.ts
Normal file
4
libs/common/src/constants/password-type.enum.ts
Normal file
@ -0,0 +1,4 @@
|
||||
export enum PasswordType {
|
||||
SINGLE = 'single',
|
||||
MULTIPLE = 'multiple',
|
||||
}
|
@ -1,9 +1,11 @@
|
||||
import { DaysEnum } from './days.enum';
|
||||
|
||||
export enum WorkingDays {
|
||||
Sun = 'Sun',
|
||||
Mon = 'Mon',
|
||||
Tue = 'Tue',
|
||||
Wed = 'Wed',
|
||||
Thu = 'Thu',
|
||||
Fri = 'Fri',
|
||||
Sat = 'Sat',
|
||||
Sun = DaysEnum.SUN,
|
||||
Mon = DaysEnum.MON,
|
||||
Tue = DaysEnum.TUE,
|
||||
Wed = DaysEnum.WED,
|
||||
Thu = DaysEnum.THU,
|
||||
Fri = DaysEnum.FRI,
|
||||
Sat = DaysEnum.SAT,
|
||||
}
|
||||
|
@ -2,10 +2,11 @@ import { Controller, Post, Param } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { AddDeviceStatusDto } from '../dtos/add.devices-status.dto';
|
||||
import { DeviceStatusFirebaseService } from '../services/devices-status.service';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@ApiTags('Device Status Firebase Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'device-status-firebase',
|
||||
})
|
||||
export class DeviceStatusFirebaseController {
|
||||
|
@ -1,3 +1,5 @@
|
||||
import { EnableDisableStatusEnum } from '../constants/days.enum';
|
||||
|
||||
export function convertTimestampToDubaiTime(timestamp) {
|
||||
// Convert timestamp to milliseconds
|
||||
const date = new Date(timestamp * 1000);
|
||||
@ -8,12 +10,24 @@ export function convertTimestampToDubaiTime(timestamp) {
|
||||
|
||||
// Format the date as YYYYMMDD
|
||||
const year = dubaiTime.getUTCFullYear();
|
||||
const month = String(dubaiTime.getUTCMonth() + 1).padStart(2, '0'); // Months are zero-based
|
||||
const day = String(dubaiTime.getUTCDate()).padStart(2, '0');
|
||||
const month = String(dubaiTime.getUTCMonth() + 1).padStart(
|
||||
2,
|
||||
EnableDisableStatusEnum.DISABLED,
|
||||
); // Months are zero-based
|
||||
const day = String(dubaiTime.getUTCDate()).padStart(
|
||||
2,
|
||||
EnableDisableStatusEnum.DISABLED,
|
||||
);
|
||||
|
||||
// Format the time as HH:MM (24-hour format)
|
||||
const hours = String(dubaiTime.getUTCHours()).padStart(2, '0');
|
||||
const minutes = String(dubaiTime.getUTCMinutes()).padStart(2, '0');
|
||||
const hours = String(dubaiTime.getUTCHours()).padStart(
|
||||
2,
|
||||
EnableDisableStatusEnum.DISABLED,
|
||||
);
|
||||
const minutes = String(dubaiTime.getUTCMinutes()).padStart(
|
||||
2,
|
||||
EnableDisableStatusEnum.DISABLED,
|
||||
);
|
||||
|
||||
// Return formatted date and time
|
||||
return {
|
||||
|
@ -1,24 +1,42 @@
|
||||
export function getScheduleStatus(daysEnabled: string[]): string {
|
||||
const daysMap: string[] = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
import { DaysEnum, EnableDisableStatusEnum } from '../constants/days.enum';
|
||||
|
||||
const schedule: string[] = Array(7).fill('0');
|
||||
export function getScheduleStatus(daysEnabled: string[]): string {
|
||||
const daysMap: string[] = [
|
||||
DaysEnum.SUN,
|
||||
DaysEnum.MON,
|
||||
DaysEnum.TUE,
|
||||
DaysEnum.WED,
|
||||
DaysEnum.THU,
|
||||
DaysEnum.FRI,
|
||||
DaysEnum.SAT,
|
||||
];
|
||||
|
||||
const schedule: string[] = Array(7).fill(EnableDisableStatusEnum.DISABLED);
|
||||
|
||||
daysEnabled.forEach((day) => {
|
||||
const index: number = daysMap.indexOf(day);
|
||||
if (index !== -1) {
|
||||
schedule[index] = '1';
|
||||
schedule[index] = EnableDisableStatusEnum.ENABLED;
|
||||
}
|
||||
});
|
||||
|
||||
return schedule.join('');
|
||||
}
|
||||
export function getEnabledDays(schedule: string): string[] {
|
||||
const daysMap: string[] = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
||||
const daysMap: string[] = [
|
||||
DaysEnum.SUN,
|
||||
DaysEnum.MON,
|
||||
DaysEnum.TUE,
|
||||
DaysEnum.WED,
|
||||
DaysEnum.THU,
|
||||
DaysEnum.FRI,
|
||||
DaysEnum.SAT,
|
||||
];
|
||||
const enabledDays: string[] = [];
|
||||
|
||||
// Iterate through the schedule string
|
||||
for (let i = 0; i < schedule.length; i++) {
|
||||
if (schedule[i] === '1') {
|
||||
if (schedule[i] === EnableDisableStatusEnum.ENABLED) {
|
||||
enabledDays.push(daysMap[i]);
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,10 @@
|
||||
import { Controller, Post } from '@nestjs/common';
|
||||
import { AuthenticationService } from '../services/authentication.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'authentication',
|
||||
})
|
||||
@ApiTags('Tuya Auth')
|
||||
|
@ -15,9 +15,10 @@ import { UserLoginDto } from '../dtos/user-login.dto';
|
||||
import { ForgetPasswordDto, UserOtpDto, VerifyOtpDto } from '../dtos';
|
||||
import { RefreshTokenGuard } from '@app/common/guards/jwt-refresh.auth.guard';
|
||||
import { SuperAdminRoleGuard } from 'src/guards/super.admin.role.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'authentication',
|
||||
})
|
||||
@ApiTags('Auth')
|
||||
|
@ -18,10 +18,11 @@ import {
|
||||
UpdateAutomationStatusDto,
|
||||
} from '../dtos/automation.dto';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@ApiTags('Automation Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'automation',
|
||||
})
|
||||
export class AutomationController {
|
||||
|
@ -23,6 +23,11 @@ import {
|
||||
GetAutomationByUnitInterface,
|
||||
} from '../interface/automation.interface';
|
||||
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import {
|
||||
ActionExecutorEnum,
|
||||
EntityTypeEnum,
|
||||
} from '@app/common/constants/automation.enum';
|
||||
|
||||
@Injectable()
|
||||
export class AutomationService {
|
||||
@ -64,7 +69,7 @@ export class AutomationService {
|
||||
);
|
||||
|
||||
for (const action of actions) {
|
||||
if (action.action_executor === 'device_issue') {
|
||||
if (action.action_executor === ActionExecutorEnum.DEVICE_ISSUE) {
|
||||
const device = await this.deviceService.getDeviceByDeviceUuid(
|
||||
action.entity_id,
|
||||
false,
|
||||
@ -76,7 +81,7 @@ export class AutomationService {
|
||||
}
|
||||
|
||||
for (const condition of conditions) {
|
||||
if (condition.entity_type === 'device_report') {
|
||||
if (condition.entity_type === EntityTypeEnum.DEVICE_REPORT) {
|
||||
const device = await this.deviceService.getDeviceByDeviceUuid(
|
||||
condition.entity_id,
|
||||
false,
|
||||
@ -127,12 +132,12 @@ export class AutomationService {
|
||||
where: {
|
||||
uuid: unitUuid,
|
||||
spaceType: {
|
||||
type: 'unit',
|
||||
type: SpaceType.UNIT,
|
||||
},
|
||||
},
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
if (!unit || !unit.spaceType || unit.spaceType.type !== 'unit') {
|
||||
if (!unit || !unit.spaceType || unit.spaceType.type !== SpaceType.UNIT) {
|
||||
throw new BadRequestException('Invalid unit UUID');
|
||||
}
|
||||
return {
|
||||
@ -240,7 +245,7 @@ export class AutomationService {
|
||||
}));
|
||||
|
||||
for (const action of actions) {
|
||||
if (action.actionExecutor === 'device_issue') {
|
||||
if (action.actionExecutor === ActionExecutorEnum.DEVICE_ISSUE) {
|
||||
const device = await this.deviceService.getDeviceByDeviceTuyaUuid(
|
||||
action.entityId,
|
||||
);
|
||||
@ -249,8 +254,8 @@ export class AutomationService {
|
||||
action.entityId = device.uuid;
|
||||
}
|
||||
} else if (
|
||||
action.actionExecutor !== 'device_issue' &&
|
||||
action.actionExecutor !== 'delay'
|
||||
action.actionExecutor !== ActionExecutorEnum.DEVICE_ISSUE &&
|
||||
action.actionExecutor !== ActionExecutorEnum.DELAY
|
||||
) {
|
||||
const sceneDetails = await this.getTapToRunSceneDetailsTuya(
|
||||
action.entityId,
|
||||
@ -268,7 +273,7 @@ export class AutomationService {
|
||||
}));
|
||||
|
||||
for (const condition of conditions) {
|
||||
if (condition.entityType === 'device_report') {
|
||||
if (condition.entityType === EntityTypeEnum.DEVICE_REPORT) {
|
||||
const device = await this.deviceService.getDeviceByDeviceTuyaUuid(
|
||||
condition.entityId,
|
||||
);
|
||||
|
@ -20,11 +20,13 @@ import { CheckUserBuildingGuard } from 'src/guards/user.building.guard';
|
||||
import { AdminRoleGuard } from 'src/guards/admin.role.guard';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { BuildingPermissionGuard } from 'src/guards/building.permission.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
|
||||
@ApiTags('Building Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
path: 'building',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: SpaceType.BUILDING,
|
||||
})
|
||||
export class BuildingController {
|
||||
constructor(private readonly buildingService: BuildingService) {}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { BooleanValues } from '@app/common/constants/boolean-values.enum';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
import {
|
||||
@ -45,7 +46,7 @@ export class GetBuildingChildDto {
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Transform((value) => {
|
||||
return value.obj.includeSubSpaces === 'true';
|
||||
return value.obj.includeSubSpaces === BooleanValues.TRUE;
|
||||
})
|
||||
public includeSubSpaces: boolean = false;
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ import {
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities';
|
||||
import { UpdateBuildingNameDto } from '../dtos/update.building.dto';
|
||||
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import { CommonErrorCodes } from '@app/common/constants/error-codes.enum';
|
||||
|
||||
@Injectable()
|
||||
export class BuildingService {
|
||||
@ -31,7 +33,7 @@ export class BuildingService {
|
||||
try {
|
||||
const spaceType = await this.spaceTypeRepository.findOne({
|
||||
where: {
|
||||
type: 'building',
|
||||
type: SpaceType.BUILDING,
|
||||
},
|
||||
});
|
||||
|
||||
@ -61,7 +63,7 @@ export class BuildingService {
|
||||
where: {
|
||||
uuid: buildingUuid,
|
||||
spaceType: {
|
||||
type: 'building',
|
||||
type: SpaceType.BUILDING,
|
||||
},
|
||||
},
|
||||
relations: ['spaceType'],
|
||||
@ -69,7 +71,7 @@ export class BuildingService {
|
||||
if (
|
||||
!building ||
|
||||
!building.spaceType ||
|
||||
building.spaceType.type !== 'building'
|
||||
building.spaceType.type !== SpaceType.BUILDING
|
||||
) {
|
||||
throw new BadRequestException('Invalid building UUID');
|
||||
}
|
||||
@ -99,7 +101,11 @@ export class BuildingService {
|
||||
where: { uuid: buildingUuid },
|
||||
relations: ['children', 'spaceType'],
|
||||
});
|
||||
if (!space || !space.spaceType || space.spaceType.type !== 'building') {
|
||||
if (
|
||||
!space ||
|
||||
!space.spaceType ||
|
||||
space.spaceType.type !== SpaceType.BUILDING
|
||||
) {
|
||||
throw new BadRequestException('Invalid building UUID');
|
||||
}
|
||||
|
||||
@ -147,8 +153,8 @@ export class BuildingService {
|
||||
return children
|
||||
.filter(
|
||||
(child) =>
|
||||
child.spaceType.type !== 'building' &&
|
||||
child.spaceType.type !== 'community',
|
||||
child.spaceType.type !== SpaceType.BUILDING &&
|
||||
child.spaceType.type !== SpaceType.COMMUNITY,
|
||||
) // Filter remaining building and community types
|
||||
.map((child) => ({
|
||||
uuid: child.uuid,
|
||||
@ -161,8 +167,8 @@ export class BuildingService {
|
||||
children
|
||||
.filter(
|
||||
(child) =>
|
||||
child.spaceType.type !== 'building' &&
|
||||
child.spaceType.type !== 'community',
|
||||
child.spaceType.type !== SpaceType.BUILDING &&
|
||||
child.spaceType.type !== SpaceType.COMMUNITY,
|
||||
) // Filter remaining building and community types
|
||||
.map(async (child) => ({
|
||||
uuid: child.uuid,
|
||||
@ -183,7 +189,7 @@ export class BuildingService {
|
||||
where: {
|
||||
uuid: buildingUuid,
|
||||
spaceType: {
|
||||
type: 'building',
|
||||
type: SpaceType.BUILDING,
|
||||
},
|
||||
},
|
||||
relations: ['spaceType', 'parent', 'parent.spaceType'],
|
||||
@ -191,7 +197,7 @@ export class BuildingService {
|
||||
if (
|
||||
!building ||
|
||||
!building.spaceType ||
|
||||
building.spaceType.type !== 'building'
|
||||
building.spaceType.type !== SpaceType.BUILDING
|
||||
) {
|
||||
throw new BadRequestException('Invalid building UUID');
|
||||
}
|
||||
@ -222,7 +228,7 @@ export class BuildingService {
|
||||
relations: ['space', 'space.spaceType'],
|
||||
where: {
|
||||
user: { uuid: userUuid },
|
||||
space: { spaceType: { type: 'building' } },
|
||||
space: { spaceType: { type: SpaceType.BUILDING } },
|
||||
},
|
||||
});
|
||||
|
||||
@ -254,7 +260,7 @@ export class BuildingService {
|
||||
space: { uuid: addUserBuildingDto.buildingUuid },
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.code === '23505') {
|
||||
if (err.code === CommonErrorCodes.DUPLICATE_ENTITY) {
|
||||
throw new HttpException(
|
||||
'User already belongs to this building',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
@ -279,7 +285,7 @@ export class BuildingService {
|
||||
if (
|
||||
!building ||
|
||||
!building.spaceType ||
|
||||
building.spaceType.type !== 'building'
|
||||
building.spaceType.type !== SpaceType.BUILDING
|
||||
) {
|
||||
throw new BadRequestException('Invalid building UUID');
|
||||
}
|
||||
|
@ -21,12 +21,14 @@ import { UpdateCommunityNameDto } from '../dtos/update.community.dto';
|
||||
// import { CheckUserCommunityGuard } from 'src/guards/user.community.guard';
|
||||
import { AdminRoleGuard } from 'src/guards/admin.role.guard';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
// import { CommunityPermissionGuard } from 'src/guards/community.permission.guard';
|
||||
|
||||
@ApiTags('Community Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
path: 'community',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: SpaceType.COMMUNITY,
|
||||
})
|
||||
export class CommunityController {
|
||||
constructor(private readonly communityService: CommunityService) {}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { BooleanValues } from '@app/common/constants/boolean-values.enum';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
import {
|
||||
@ -45,7 +46,7 @@ export class GetCommunityChildDto {
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Transform((value) => {
|
||||
return value.obj.includeSubSpaces === 'true';
|
||||
return value.obj.includeSubSpaces === BooleanValues.TRUE;
|
||||
})
|
||||
public includeSubSpaces: boolean = false;
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ import {
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities';
|
||||
import { UpdateCommunityNameDto } from '../dtos/update.community.dto';
|
||||
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import { CommonErrorCodes } from '@app/common/constants/error-codes.enum';
|
||||
|
||||
@Injectable()
|
||||
export class CommunityService {
|
||||
@ -31,7 +33,7 @@ export class CommunityService {
|
||||
try {
|
||||
const spaceType = await this.spaceTypeRepository.findOne({
|
||||
where: {
|
||||
type: 'community',
|
||||
type: SpaceType.COMMUNITY,
|
||||
},
|
||||
});
|
||||
|
||||
@ -53,7 +55,7 @@ export class CommunityService {
|
||||
where: {
|
||||
uuid: communityUuid,
|
||||
spaceType: {
|
||||
type: 'community',
|
||||
type: SpaceType.COMMUNITY,
|
||||
},
|
||||
},
|
||||
relations: ['spaceType'],
|
||||
@ -61,7 +63,7 @@ export class CommunityService {
|
||||
if (
|
||||
!community ||
|
||||
!community.spaceType ||
|
||||
community.spaceType.type !== 'community'
|
||||
community.spaceType.type !== SpaceType.COMMUNITY
|
||||
) {
|
||||
throw new BadRequestException('Invalid community UUID');
|
||||
}
|
||||
@ -83,7 +85,7 @@ export class CommunityService {
|
||||
async getCommunities(): Promise<GetCommunitiesInterface> {
|
||||
try {
|
||||
const community = await this.spaceRepository.find({
|
||||
where: { spaceType: { type: 'community' } },
|
||||
where: { spaceType: { type: SpaceType.COMMUNITY } },
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
return community.map((community) => ({
|
||||
@ -109,7 +111,11 @@ export class CommunityService {
|
||||
relations: ['children', 'spaceType'],
|
||||
});
|
||||
|
||||
if (!space || !space.spaceType || space.spaceType.type !== 'community') {
|
||||
if (
|
||||
!space ||
|
||||
!space.spaceType ||
|
||||
space.spaceType.type !== SpaceType.COMMUNITY
|
||||
) {
|
||||
throw new BadRequestException('Invalid community UUID');
|
||||
}
|
||||
const totalCount = await this.spaceRepository.count({
|
||||
@ -152,7 +158,7 @@ export class CommunityService {
|
||||
|
||||
if (!children || children.length === 0 || !includeSubSpaces) {
|
||||
return children
|
||||
.filter((child) => child.spaceType.type !== 'community') // Filter remaining community type
|
||||
.filter((child) => child.spaceType.type !== SpaceType.COMMUNITY) // Filter remaining community type
|
||||
.map((child) => ({
|
||||
uuid: child.uuid,
|
||||
name: child.spaceName,
|
||||
@ -162,7 +168,7 @@ export class CommunityService {
|
||||
|
||||
const childHierarchies = await Promise.all(
|
||||
children
|
||||
.filter((child) => child.spaceType.type !== 'community') // Filter remaining community type
|
||||
.filter((child) => child.spaceType.type !== SpaceType.COMMUNITY) // Filter remaining community type
|
||||
.map(async (child) => ({
|
||||
uuid: child.uuid,
|
||||
name: child.spaceName,
|
||||
@ -182,7 +188,7 @@ export class CommunityService {
|
||||
relations: ['space', 'space.spaceType'],
|
||||
where: {
|
||||
user: { uuid: userUuid },
|
||||
space: { spaceType: { type: 'community' } },
|
||||
space: { spaceType: { type: SpaceType.COMMUNITY } },
|
||||
},
|
||||
});
|
||||
|
||||
@ -215,7 +221,7 @@ export class CommunityService {
|
||||
space: { uuid: addUserCommunityDto.communityUuid },
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.code === '23505') {
|
||||
if (err.code === CommonErrorCodes.DUPLICATE_ENTITY) {
|
||||
throw new HttpException(
|
||||
'User already belongs to this community',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
@ -240,7 +246,7 @@ export class CommunityService {
|
||||
if (
|
||||
!community ||
|
||||
!community.spaceType ||
|
||||
community.spaceType.type !== 'community'
|
||||
community.spaceType.type !== SpaceType.COMMUNITY
|
||||
) {
|
||||
throw new BadRequestException('Invalid community UUID');
|
||||
}
|
||||
|
@ -14,10 +14,11 @@ import { DeviceMessagesSubscriptionService } from '../services/device-messages.s
|
||||
import { DeviceMessagesAddDto } from '../dtos/device-messages.dto';
|
||||
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@ApiTags('Device Messages Status Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'device-messages/subscription',
|
||||
})
|
||||
export class DeviceMessagesSubscriptionController {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { DeviceMessagesAddDto } from '../dtos/device-messages.dto';
|
||||
import { DeviceNotificationRepository } from '@app/common/modules/device/repositories';
|
||||
import { CommonErrorCodes } from '@app/common/constants/error-codes.enum';
|
||||
|
||||
@Injectable()
|
||||
export class DeviceMessagesSubscriptionService {
|
||||
@ -21,7 +22,7 @@ export class DeviceMessagesSubscriptionService {
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code === '23505') {
|
||||
if (error.code === CommonErrorCodes.DUPLICATE_ENTITY) {
|
||||
throw new HttpException(
|
||||
'This User already belongs to this device',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
|
@ -30,10 +30,12 @@ import { CheckUserHaveControllablePermission } from 'src/guards/user.device.cont
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { CheckDeviceGuard } from 'src/guards/device.guard';
|
||||
import { SuperAdminRoleGuard } from 'src/guards/super.admin.role.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
|
||||
@ApiTags('Device Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'device',
|
||||
})
|
||||
export class DeviceController {
|
||||
@ -73,7 +75,7 @@ export class DeviceController {
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard, CheckRoomGuard)
|
||||
@Get('room')
|
||||
@Get(SpaceType.ROOM)
|
||||
async getDevicesByRoomId(
|
||||
@Query() getDeviceByRoomUuidDto: GetDeviceByRoomUuidDto,
|
||||
@Req() req: any,
|
||||
|
@ -35,6 +35,8 @@ import { In } from 'typeorm';
|
||||
import { ProductType } from '@app/common/constants/product-type.enum';
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { DeviceStatusFirebaseService } from '@app/common/firebase/devices-status/services/devices-status.service';
|
||||
import { DeviceStatuses } from '@app/common/constants/device-status.enum';
|
||||
import { CommonErrorCodes } from '@app/common/constants/error-codes.enum';
|
||||
|
||||
@Injectable()
|
||||
export class DeviceService {
|
||||
@ -106,7 +108,7 @@ export class DeviceService {
|
||||
}
|
||||
return deviceSaved;
|
||||
} catch (error) {
|
||||
if (error.code === '23505') {
|
||||
if (error.code === CommonErrorCodes.DUPLICATE_ENTITY) {
|
||||
throw new HttpException(
|
||||
'Device already exists',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
@ -355,7 +357,7 @@ export class DeviceService {
|
||||
const failedResults = [];
|
||||
|
||||
for (const result of results) {
|
||||
if (result.status === 'fulfilled') {
|
||||
if (result.status === DeviceStatuses.FULLFILLED) {
|
||||
const { deviceUuid, result: operationResult } = result.value;
|
||||
|
||||
if (operationResult.success) {
|
||||
@ -457,7 +459,7 @@ export class DeviceService {
|
||||
const failedResults = [];
|
||||
|
||||
for (const result of results) {
|
||||
if (result.status === 'fulfilled') {
|
||||
if (result.status === DeviceStatuses.FULLFILLED) {
|
||||
const { deviceUuid, result: operationResult } = result.value;
|
||||
|
||||
if (operationResult.success) {
|
||||
@ -819,7 +821,8 @@ export class DeviceService {
|
||||
await this.getDevicesInstructionStatus(device.uuid);
|
||||
|
||||
const batteryStatus: any = doorLockInstructionsStatus.status.find(
|
||||
(status: any) => status.code === 'residual_electricity',
|
||||
(status: any) =>
|
||||
status.code === batteryStatus.RESIDUAL_ELECTRICITY,
|
||||
);
|
||||
|
||||
if (batteryStatus) {
|
||||
@ -832,7 +835,7 @@ export class DeviceService {
|
||||
await this.getDevicesInstructionStatus(device.uuid);
|
||||
|
||||
const batteryStatus: any = doorSensorInstructionsStatus.status.find(
|
||||
(status: any) => status.code === 'battery_percentage',
|
||||
(status: any) => status.code === batteryStatus.BATTERY_PERCENTAGE,
|
||||
);
|
||||
|
||||
if (batteryStatus) {
|
||||
@ -845,7 +848,7 @@ export class DeviceService {
|
||||
await this.getDevicesInstructionStatus(device.uuid);
|
||||
|
||||
const batteryStatus: any = doorSensorInstructionsStatus.status.find(
|
||||
(status: any) => status.code === 'battery_percentage',
|
||||
(status: any) => status.code === batteryStatus.BATTERY_PERCENTAGE,
|
||||
);
|
||||
|
||||
if (batteryStatus) {
|
||||
@ -877,7 +880,7 @@ export class DeviceService {
|
||||
|
||||
// Filter out rejected promises and extract the fulfilled values
|
||||
const fulfilledDevices = devicesData
|
||||
.filter((result) => result.status === 'fulfilled')
|
||||
.filter((result) => result.status === DeviceStatuses.FULLFILLED)
|
||||
.map(
|
||||
(result) =>
|
||||
(result as PromiseFulfilledResult<GetDeviceDetailsInterface>).value,
|
||||
|
@ -16,10 +16,11 @@ import { AddDoorLockOnlineDto } from '../dtos/add.online-temp.dto';
|
||||
import { AddDoorLockOfflineTempMultipleTimeDto } from '../dtos/add.offline-temp.dto';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { UpdateDoorLockOfflineTempDto } from '../dtos/update.offline-temp.dto';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@ApiTags('Door Lock Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'door-lock',
|
||||
})
|
||||
export class DoorLockController {
|
||||
|
@ -24,6 +24,15 @@ import { UpdateDoorLockOfflineTempDto } from '../dtos/update.offline-temp.dto';
|
||||
import { defaultDoorLockPass } from '@app/common/constants/default.door-lock-pass';
|
||||
import { VisitorPasswordRepository } from '@app/common/modules/visitor-password/repositories';
|
||||
import { DeviceService } from 'src/device/services';
|
||||
import {
|
||||
DaysEnum,
|
||||
EnableDisableStatusEnum,
|
||||
} from '@app/common/constants/days.enum';
|
||||
import { PasswordType } from '@app/common/constants/password-type.enum';
|
||||
import {
|
||||
CommonHourMinutes,
|
||||
CommonHours,
|
||||
} from '@app/common/constants/hours-minutes.enum';
|
||||
|
||||
@Injectable()
|
||||
export class DoorLockService {
|
||||
@ -115,7 +124,7 @@ export class DoorLockService {
|
||||
);
|
||||
const passwords = await this.getTemporaryOfflinePasswordsTuya(
|
||||
deviceDetails.deviceTuyaUuid,
|
||||
'multiple',
|
||||
PasswordType.MULTIPLE,
|
||||
isExpired,
|
||||
);
|
||||
if (!passwords.result.records.length && fromVisitor) {
|
||||
@ -502,7 +511,7 @@ export class DoorLockService {
|
||||
}
|
||||
const createOnceOfflinePass = await this.addOfflineTemporaryPasswordTuya(
|
||||
deviceDetails.deviceTuyaUuid,
|
||||
'multiple',
|
||||
PasswordType.MULTIPLE,
|
||||
addDoorLockOfflineTempMultipleTimeDto,
|
||||
);
|
||||
if (!createOnceOfflinePass.success) {
|
||||
@ -566,7 +575,7 @@ export class DoorLockService {
|
||||
method: 'POST',
|
||||
path,
|
||||
body: {
|
||||
...(type === 'multiple' && {
|
||||
...(type === PasswordType.MULTIPLE && {
|
||||
effective_time: addDoorLockOfflineTempMultipleTimeDto.effectiveTime,
|
||||
invalid_time: addDoorLockOfflineTempMultipleTimeDto.invalidTime,
|
||||
}),
|
||||
@ -711,7 +720,7 @@ export class DoorLockService {
|
||||
schedule_list: scheduleList,
|
||||
}),
|
||||
|
||||
type: '0',
|
||||
type: EnableDisableStatusEnum.DISABLED,
|
||||
},
|
||||
});
|
||||
|
||||
@ -725,7 +734,15 @@ export class DoorLockService {
|
||||
}
|
||||
getWorkingDayValue(days) {
|
||||
// Array representing the days of the week
|
||||
const weekDays = ['Sat', 'Fri', 'Thu', 'Wed', 'Tue', 'Mon', 'Sun'];
|
||||
const weekDays = [
|
||||
DaysEnum.SAT,
|
||||
DaysEnum.FRI,
|
||||
DaysEnum.THU,
|
||||
DaysEnum.WED,
|
||||
DaysEnum.TUE,
|
||||
DaysEnum.MON,
|
||||
DaysEnum.SUN,
|
||||
];
|
||||
|
||||
// Initialize a binary string with 7 bits
|
||||
let binaryString = '0000000';
|
||||
@ -734,10 +751,10 @@ export class DoorLockService {
|
||||
days.forEach((day) => {
|
||||
const index = weekDays.indexOf(day);
|
||||
if (index !== -1) {
|
||||
// Set the corresponding bit to '1'
|
||||
// Set the corresponding bit to EnableDisableStatusEnum.ENABLED
|
||||
binaryString =
|
||||
binaryString.substring(0, index) +
|
||||
'1' +
|
||||
EnableDisableStatusEnum.ENABLED +
|
||||
binaryString.substring(index + 1);
|
||||
}
|
||||
});
|
||||
@ -749,17 +766,27 @@ export class DoorLockService {
|
||||
}
|
||||
getDaysFromWorkingDayValue(workingDayValue) {
|
||||
// Array representing the days of the week
|
||||
const weekDays = ['Sat', 'Fri', 'Thu', 'Wed', 'Tue', 'Mon', 'Sun'];
|
||||
const weekDays = [
|
||||
DaysEnum.SAT,
|
||||
DaysEnum.FRI,
|
||||
DaysEnum.THU,
|
||||
DaysEnum.WED,
|
||||
DaysEnum.TUE,
|
||||
DaysEnum.MON,
|
||||
DaysEnum.SUN,
|
||||
];
|
||||
|
||||
// Convert the integer to a binary string and pad with leading zeros to ensure 7 bits
|
||||
const binaryString = workingDayValue.toString(2).padStart(7, '0');
|
||||
const binaryString = workingDayValue
|
||||
.toString(2)
|
||||
.padStart(7, EnableDisableStatusEnum.DISABLED);
|
||||
|
||||
// Initialize an array to hold the days of the week
|
||||
const days = [];
|
||||
|
||||
// Iterate through the binary string and weekDays array
|
||||
for (let i = 0; i < binaryString.length; i++) {
|
||||
if (binaryString[i] === '1') {
|
||||
if (binaryString[i] === EnableDisableStatusEnum.ENABLED) {
|
||||
days.push(weekDays[i]);
|
||||
}
|
||||
}
|
||||
@ -769,8 +796,8 @@ export class DoorLockService {
|
||||
timeToMinutes(timeStr) {
|
||||
try {
|
||||
// Special case for "24:00"
|
||||
if (timeStr === '24:00') {
|
||||
return 1440;
|
||||
if (timeStr === CommonHours.TWENTY_FOUR) {
|
||||
return CommonHourMinutes.TWENTY_FOUR;
|
||||
}
|
||||
|
||||
// Regular expression to validate the 24-hour time format (HH:MM)
|
||||
@ -798,20 +825,26 @@ export class DoorLockService {
|
||||
if (
|
||||
typeof totalMinutes !== 'number' ||
|
||||
totalMinutes < 0 ||
|
||||
totalMinutes > 1440
|
||||
totalMinutes > CommonHourMinutes.TWENTY_FOUR
|
||||
) {
|
||||
throw new Error('Invalid minutes value');
|
||||
}
|
||||
|
||||
if (totalMinutes === 1440) {
|
||||
return '24:00';
|
||||
if (totalMinutes === CommonHourMinutes.TWENTY_FOUR) {
|
||||
return CommonHours.TWENTY_FOUR;
|
||||
}
|
||||
|
||||
const hours = Math.floor(totalMinutes / 60);
|
||||
const minutes = totalMinutes % 60;
|
||||
|
||||
const formattedHours = String(hours).padStart(2, '0');
|
||||
const formattedMinutes = String(minutes).padStart(2, '0');
|
||||
const formattedHours = String(hours).padStart(
|
||||
2,
|
||||
EnableDisableStatusEnum.DISABLED,
|
||||
);
|
||||
const formattedMinutes = String(minutes).padStart(
|
||||
2,
|
||||
EnableDisableStatusEnum.DISABLED,
|
||||
);
|
||||
|
||||
return `${formattedHours}:${formattedMinutes}`;
|
||||
} catch (error) {
|
||||
|
@ -1,6 +1,7 @@
|
||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import * as CryptoJS from 'crypto-js';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@Injectable()
|
||||
export class PasswordEncryptionService {
|
||||
@ -43,7 +44,9 @@ export class PasswordEncryptionService {
|
||||
'auth-config.SECRET_KEY',
|
||||
);
|
||||
// The accessSecret must be 32 bytes, ensure it is properly padded or truncated
|
||||
const paddedAccessSecret = accessSecret.padEnd(32, '0').slice(0, 32);
|
||||
const paddedAccessSecret = accessSecret
|
||||
.padEnd(32, EnableDisableStatusEnum.DISABLED)
|
||||
.slice(0, 32);
|
||||
const plainTextTicketKey = this.decrypt(ticketKey, paddedAccessSecret);
|
||||
|
||||
return this.encrypt(plainTextPassword, plainTextTicketKey);
|
||||
|
@ -20,11 +20,13 @@ import { CheckUserFloorGuard } from 'src/guards/user.floor.guard';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { AdminRoleGuard } from 'src/guards/admin.role.guard';
|
||||
import { FloorPermissionGuard } from 'src/guards/floor.permission.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
|
||||
@ApiTags('Floor Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
path: 'floor',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: SpaceType.FLOOR,
|
||||
})
|
||||
export class FloorController {
|
||||
constructor(private readonly floorService: FloorService) {}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { BooleanValues } from '@app/common/constants/boolean-values.enum';
|
||||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
import {
|
||||
@ -45,7 +46,7 @@ export class GetFloorChildDto {
|
||||
@IsOptional()
|
||||
@IsBoolean()
|
||||
@Transform((value) => {
|
||||
return value.obj.includeSubSpaces === 'true';
|
||||
return value.obj.includeSubSpaces === BooleanValues.TRUE;
|
||||
})
|
||||
public includeSubSpaces: boolean = false;
|
||||
}
|
||||
|
@ -18,6 +18,8 @@ import {
|
||||
import { SpaceEntity } from '@app/common/modules/space/entities';
|
||||
import { UpdateFloorNameDto } from '../dtos/update.floor.dto';
|
||||
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import { CommonErrorCodes } from '@app/common/constants/error-codes.enum';
|
||||
|
||||
@Injectable()
|
||||
export class FloorService {
|
||||
@ -31,7 +33,7 @@ export class FloorService {
|
||||
try {
|
||||
const spaceType = await this.spaceTypeRepository.findOne({
|
||||
where: {
|
||||
type: 'floor',
|
||||
type: SpaceType.FLOOR,
|
||||
},
|
||||
});
|
||||
|
||||
@ -52,12 +54,16 @@ export class FloorService {
|
||||
where: {
|
||||
uuid: floorUuid,
|
||||
spaceType: {
|
||||
type: 'floor',
|
||||
type: SpaceType.FLOOR,
|
||||
},
|
||||
},
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
if (!floor || !floor.spaceType || floor.spaceType.type !== 'floor') {
|
||||
if (
|
||||
!floor ||
|
||||
!floor.spaceType ||
|
||||
floor.spaceType.type !== SpaceType.FLOOR
|
||||
) {
|
||||
throw new BadRequestException('Invalid floor UUID');
|
||||
}
|
||||
|
||||
@ -88,7 +94,11 @@ export class FloorService {
|
||||
relations: ['children', 'spaceType'],
|
||||
});
|
||||
|
||||
if (!space || !space.spaceType || space.spaceType.type !== 'floor') {
|
||||
if (
|
||||
!space ||
|
||||
!space.spaceType ||
|
||||
space.spaceType.type !== SpaceType.FLOOR
|
||||
) {
|
||||
throw new BadRequestException('Invalid floor UUID');
|
||||
}
|
||||
const totalCount = await this.spaceRepository.count({
|
||||
@ -135,9 +145,9 @@ export class FloorService {
|
||||
return children
|
||||
.filter(
|
||||
(child) =>
|
||||
child.spaceType.type !== 'floor' &&
|
||||
child.spaceType.type !== 'building' &&
|
||||
child.spaceType.type !== 'community',
|
||||
child.spaceType.type !== SpaceType.FLOOR &&
|
||||
child.spaceType.type !== SpaceType.BUILDING &&
|
||||
child.spaceType.type !== SpaceType.COMMUNITY,
|
||||
) // Filter remaining floor and building and community types
|
||||
.map((child) => ({
|
||||
uuid: child.uuid,
|
||||
@ -150,9 +160,9 @@ export class FloorService {
|
||||
children
|
||||
.filter(
|
||||
(child) =>
|
||||
child.spaceType.type !== 'floor' &&
|
||||
child.spaceType.type !== 'building' &&
|
||||
child.spaceType.type !== 'community',
|
||||
child.spaceType.type !== SpaceType.FLOOR &&
|
||||
child.spaceType.type !== SpaceType.BUILDING &&
|
||||
child.spaceType.type !== SpaceType.COMMUNITY,
|
||||
) // Filter remaining floor and building and community types
|
||||
.map(async (child) => ({
|
||||
uuid: child.uuid,
|
||||
@ -171,12 +181,16 @@ export class FloorService {
|
||||
where: {
|
||||
uuid: floorUuid,
|
||||
spaceType: {
|
||||
type: 'floor',
|
||||
type: SpaceType.FLOOR,
|
||||
},
|
||||
},
|
||||
relations: ['spaceType', 'parent', 'parent.spaceType'],
|
||||
});
|
||||
if (!floor || !floor.spaceType || floor.spaceType.type !== 'floor') {
|
||||
if (
|
||||
!floor ||
|
||||
!floor.spaceType ||
|
||||
floor.spaceType.type !== SpaceType.FLOOR
|
||||
) {
|
||||
throw new BadRequestException('Invalid floor UUID');
|
||||
}
|
||||
|
||||
@ -207,7 +221,7 @@ export class FloorService {
|
||||
relations: ['space', 'space.spaceType'],
|
||||
where: {
|
||||
user: { uuid: userUuid },
|
||||
space: { spaceType: { type: 'floor' } },
|
||||
space: { spaceType: { type: SpaceType.FLOOR } },
|
||||
},
|
||||
});
|
||||
|
||||
@ -239,7 +253,7 @@ export class FloorService {
|
||||
space: { uuid: addUserFloorDto.floorUuid },
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.code === '23505') {
|
||||
if (err.code === CommonErrorCodes.DUPLICATE_ENTITY) {
|
||||
throw new HttpException(
|
||||
'User already belongs to this floor',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
@ -261,7 +275,11 @@ export class FloorService {
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
|
||||
if (!floor || !floor.spaceType || floor.spaceType.type !== 'floor') {
|
||||
if (
|
||||
!floor ||
|
||||
!floor.spaceType ||
|
||||
floor.spaceType.type !== SpaceType.FLOOR
|
||||
) {
|
||||
throw new BadRequestException('Invalid floor UUID');
|
||||
}
|
||||
|
||||
|
@ -11,10 +11,11 @@ import {
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { UnitPermissionGuard } from 'src/guards/unit.permission.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@ApiTags('Group Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'group',
|
||||
})
|
||||
export class GroupController {
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import { SpacePermissionService } from '@app/common/helper/services/space.permission.service';
|
||||
import {
|
||||
BadRequestException,
|
||||
@ -24,7 +25,7 @@ export class BuildingPermissionGuard implements CanActivate {
|
||||
await this.permissionService.checkUserPermission(
|
||||
buildingUuid,
|
||||
user.uuid,
|
||||
'building',
|
||||
SpaceType.BUILDING,
|
||||
);
|
||||
|
||||
return true;
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import {
|
||||
Injectable,
|
||||
@ -42,7 +43,7 @@ export class CheckBuildingTypeGuard implements CanActivate {
|
||||
if (
|
||||
!buildingData ||
|
||||
!buildingData.spaceType ||
|
||||
buildingData.spaceType.type !== 'building'
|
||||
buildingData.spaceType.type !== SpaceType.BUILDING
|
||||
) {
|
||||
throw new BadRequestException('Invalid building UUID');
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import { SpacePermissionService } from '@app/common/helper/services/space.permission.service';
|
||||
import {
|
||||
BadRequestException,
|
||||
@ -24,7 +25,7 @@ export class CommunityPermissionGuard implements CanActivate {
|
||||
await this.permissionService.checkUserPermission(
|
||||
communityUuid,
|
||||
user.uuid,
|
||||
'community',
|
||||
SpaceType.COMMUNITY,
|
||||
);
|
||||
|
||||
return true;
|
||||
|
@ -6,6 +6,7 @@ import {
|
||||
} from '@nestjs/common';
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { BadRequestException } from '@nestjs/common';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
|
||||
@Injectable()
|
||||
export class CheckCommunityTypeGuard implements CanActivate {
|
||||
@ -43,7 +44,7 @@ export class CheckCommunityTypeGuard implements CanActivate {
|
||||
if (
|
||||
!communityData ||
|
||||
!communityData.spaceType ||
|
||||
communityData.spaceType.type !== 'community'
|
||||
communityData.spaceType.type !== SpaceType.COMMUNITY
|
||||
) {
|
||||
throw new BadRequestException('Invalid community UUID');
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import { SpacePermissionService } from '@app/common/helper/services/space.permission.service';
|
||||
import {
|
||||
BadRequestException,
|
||||
@ -24,7 +25,7 @@ export class FloorPermissionGuard implements CanActivate {
|
||||
await this.permissionService.checkUserPermission(
|
||||
floorUuid,
|
||||
user.uuid,
|
||||
'floor',
|
||||
SpaceType.FLOOR,
|
||||
);
|
||||
|
||||
return true;
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import {
|
||||
Injectable,
|
||||
@ -42,7 +43,7 @@ export class CheckFloorTypeGuard implements CanActivate {
|
||||
if (
|
||||
!floorData ||
|
||||
!floorData.spaceType ||
|
||||
floorData.spaceType.type !== 'floor'
|
||||
floorData.spaceType.type !== SpaceType.FLOOR
|
||||
) {
|
||||
throw new BadRequestException('Invalid floor UUID');
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { BadRequestException, NotFoundException } from '@nestjs/common';
|
||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
|
||||
@Injectable()
|
||||
export class CheckRoomGuard implements CanActivate {
|
||||
@ -43,7 +44,7 @@ export class CheckRoomGuard implements CanActivate {
|
||||
where: {
|
||||
uuid: roomUuid,
|
||||
spaceType: {
|
||||
type: 'room',
|
||||
type: SpaceType.ROOM,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import { SpacePermissionService } from '@app/common/helper/services/space.permission.service';
|
||||
import {
|
||||
BadRequestException,
|
||||
@ -24,7 +25,7 @@ export class RoomPermissionGuard implements CanActivate {
|
||||
await this.permissionService.checkUserPermission(
|
||||
roomUuid,
|
||||
user.uuid,
|
||||
'room',
|
||||
SpaceType.ROOM,
|
||||
);
|
||||
|
||||
return true;
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import { SpacePermissionService } from '@app/common/helper/services/space.permission.service';
|
||||
import {
|
||||
BadRequestException,
|
||||
@ -24,7 +25,7 @@ export class UnitPermissionGuard implements CanActivate {
|
||||
await this.permissionService.checkUserPermission(
|
||||
unitUuid,
|
||||
user.uuid,
|
||||
'unit',
|
||||
SpaceType.UNIT,
|
||||
);
|
||||
|
||||
return true;
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import {
|
||||
Injectable,
|
||||
@ -42,7 +43,7 @@ export class CheckUnitTypeGuard implements CanActivate {
|
||||
if (
|
||||
!unitData ||
|
||||
!unitData.spaceType ||
|
||||
unitData.spaceType.type !== 'unit'
|
||||
unitData.spaceType.type !== SpaceType.UNIT
|
||||
) {
|
||||
throw new BadRequestException('Invalid unit UUID');
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { BadRequestException, NotFoundException } from '@nestjs/common';
|
||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
|
||||
@Injectable()
|
||||
export class CheckUserBuildingGuard implements CanActivate {
|
||||
@ -43,7 +44,7 @@ export class CheckUserBuildingGuard implements CanActivate {
|
||||
|
||||
private async checkBuildingIsFound(spaceUuid: string) {
|
||||
const spaceData = await this.spaceRepository.findOne({
|
||||
where: { uuid: spaceUuid, spaceType: { type: 'building' } },
|
||||
where: { uuid: spaceUuid, spaceType: { type: SpaceType.BUILDING } },
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
if (!spaceData) {
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { BadRequestException, NotFoundException } from '@nestjs/common';
|
||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
|
||||
@Injectable()
|
||||
export class CheckUserCommunityGuard implements CanActivate {
|
||||
@ -43,7 +44,7 @@ export class CheckUserCommunityGuard implements CanActivate {
|
||||
|
||||
private async checkCommunityIsFound(spaceUuid: string) {
|
||||
const spaceData = await this.spaceRepository.findOne({
|
||||
where: { uuid: spaceUuid, spaceType: { type: 'community' } },
|
||||
where: { uuid: spaceUuid, spaceType: { type: SpaceType.COMMUNITY } },
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
if (!spaceData) {
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { BadRequestException, NotFoundException } from '@nestjs/common';
|
||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
|
||||
@Injectable()
|
||||
export class CheckUserFloorGuard implements CanActivate {
|
||||
@ -43,7 +44,7 @@ export class CheckUserFloorGuard implements CanActivate {
|
||||
|
||||
private async checkFloorIsFound(spaceUuid: string) {
|
||||
const spaceData = await this.spaceRepository.findOne({
|
||||
where: { uuid: spaceUuid, spaceType: { type: 'floor' } },
|
||||
where: { uuid: spaceUuid, spaceType: { type: SpaceType.FLOOR } },
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
if (!spaceData) {
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { BadRequestException, NotFoundException } from '@nestjs/common';
|
||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
|
||||
@Injectable()
|
||||
export class CheckUserRoomGuard implements CanActivate {
|
||||
@ -43,7 +44,7 @@ export class CheckUserRoomGuard implements CanActivate {
|
||||
|
||||
private async checkRoomIsFound(spaceUuid: string) {
|
||||
const spaceData = await this.spaceRepository.findOne({
|
||||
where: { uuid: spaceUuid, spaceType: { type: 'room' } },
|
||||
where: { uuid: spaceUuid, spaceType: { type: SpaceType.ROOM } },
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
if (!spaceData) {
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
import { SpaceRepository } from '@app/common/modules/space/repositories';
|
||||
import { BadRequestException, NotFoundException } from '@nestjs/common';
|
||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
|
||||
@Injectable()
|
||||
export class CheckUserUnitGuard implements CanActivate {
|
||||
@ -43,7 +44,7 @@ export class CheckUserUnitGuard implements CanActivate {
|
||||
|
||||
private async checkUnitIsFound(spaceUuid: string) {
|
||||
const spaceData = await this.spaceRepository.findOne({
|
||||
where: { uuid: spaceUuid, spaceType: { type: 'unit' } },
|
||||
where: { uuid: spaceUuid, spaceType: { type: SpaceType.UNIT } },
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
if (!spaceData) {
|
||||
|
@ -2,10 +2,11 @@ import { Controller, Get, HttpException, HttpStatus } from '@nestjs/common';
|
||||
import { RegionService } from '../services/region.service';
|
||||
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@ApiTags('Region Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: ControllerRoute.REGION.ROUTE,
|
||||
})
|
||||
export class RegionController {
|
||||
|
@ -11,10 +11,11 @@ import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { RoleService } from '../services/role.service';
|
||||
import { AddUserRoleDto } from '../dtos';
|
||||
import { SuperAdminRoleGuard } from 'src/guards/super.admin.role.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@ApiTags('Role Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'role',
|
||||
})
|
||||
export class RoleController {
|
||||
|
@ -3,6 +3,7 @@ import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
||||
import { AddUserRoleDto } from '../dtos/role.add.dto';
|
||||
import { UserRoleRepository } from '@app/common/modules/user/repositories';
|
||||
import { QueryFailedError } from 'typeorm';
|
||||
import { CommonErrorCodes } from '@app/common/constants/error-codes.enum';
|
||||
|
||||
@Injectable()
|
||||
export class RoleService {
|
||||
@ -24,7 +25,7 @@ export class RoleService {
|
||||
} catch (error) {
|
||||
if (
|
||||
error instanceof QueryFailedError &&
|
||||
error.driverError.code === '23505'
|
||||
error.driverError.code === CommonErrorCodes.DUPLICATE_ENTITY
|
||||
) {
|
||||
// Postgres unique constraint violation error code
|
||||
throw new HttpException(
|
||||
|
@ -18,11 +18,13 @@ import { CheckUserRoomGuard } from 'src/guards/user.room.guard';
|
||||
import { AdminRoleGuard } from 'src/guards/admin.role.guard';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { RoomPermissionGuard } from 'src/guards/room.permission.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
|
||||
@ApiTags('Room Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
path: 'room',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: SpaceType.ROOM,
|
||||
})
|
||||
export class RoomController {
|
||||
constructor(private readonly roomService: RoomService) {}
|
||||
|
@ -15,6 +15,8 @@ import {
|
||||
} from '../interface/room.interface';
|
||||
import { UpdateRoomNameDto } from '../dtos/update.room.dto';
|
||||
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import { CommonErrorCodes } from '@app/common/constants/error-codes.enum';
|
||||
|
||||
@Injectable()
|
||||
export class RoomService {
|
||||
@ -28,7 +30,7 @@ export class RoomService {
|
||||
try {
|
||||
const spaceType = await this.spaceTypeRepository.findOne({
|
||||
where: {
|
||||
type: 'room',
|
||||
type: SpaceType.ROOM,
|
||||
},
|
||||
});
|
||||
|
||||
@ -49,12 +51,12 @@ export class RoomService {
|
||||
where: {
|
||||
uuid: roomUuid,
|
||||
spaceType: {
|
||||
type: 'room',
|
||||
type: SpaceType.ROOM,
|
||||
},
|
||||
},
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
if (!room || !room.spaceType || room.spaceType.type !== 'room') {
|
||||
if (!room || !room.spaceType || room.spaceType.type !== SpaceType.ROOM) {
|
||||
throw new BadRequestException('Invalid room UUID');
|
||||
}
|
||||
|
||||
@ -80,12 +82,12 @@ export class RoomService {
|
||||
where: {
|
||||
uuid: roomUuid,
|
||||
spaceType: {
|
||||
type: 'room',
|
||||
type: SpaceType.ROOM,
|
||||
},
|
||||
},
|
||||
relations: ['spaceType', 'parent', 'parent.spaceType'],
|
||||
});
|
||||
if (!room || !room.spaceType || room.spaceType.type !== 'room') {
|
||||
if (!room || !room.spaceType || room.spaceType.type !== SpaceType.ROOM) {
|
||||
throw new BadRequestException('Invalid room UUID');
|
||||
}
|
||||
|
||||
@ -116,7 +118,7 @@ export class RoomService {
|
||||
relations: ['space', 'space.spaceType'],
|
||||
where: {
|
||||
user: { uuid: userUuid },
|
||||
space: { spaceType: { type: 'room' } },
|
||||
space: { spaceType: { type: SpaceType.ROOM } },
|
||||
},
|
||||
});
|
||||
|
||||
@ -145,7 +147,7 @@ export class RoomService {
|
||||
space: { uuid: addUserRoomDto.roomUuid },
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.code === '23505') {
|
||||
if (err.code === CommonErrorCodes.DUPLICATE_ENTITY) {
|
||||
throw new HttpException(
|
||||
'User already belongs to this room',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
@ -167,7 +169,7 @@ export class RoomService {
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
|
||||
if (!room || !room.spaceType || room.spaceType.type !== 'room') {
|
||||
if (!room || !room.spaceType || room.spaceType.type !== SpaceType.ROOM) {
|
||||
throw new BadRequestException('Invalid room UUID');
|
||||
}
|
||||
|
||||
|
@ -14,10 +14,11 @@ import {
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { AddSceneTapToRunDto, UpdateSceneTapToRunDto } from '../dtos/scene.dto';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@ApiTags('Scene Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'scene',
|
||||
})
|
||||
export class SceneController {
|
||||
|
@ -18,6 +18,8 @@ import {
|
||||
SceneDetailsResult,
|
||||
} from '../interface/scene.interface';
|
||||
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import { ActionExecutorEnum } from '@app/common/constants/automation.enum';
|
||||
|
||||
@Injectable()
|
||||
export class SceneService {
|
||||
@ -63,7 +65,7 @@ export class SceneService {
|
||||
|
||||
const convertedData = convertKeysToSnakeCase(actions);
|
||||
for (const action of convertedData) {
|
||||
if (action.action_executor === 'device_issue') {
|
||||
if (action.action_executor === ActionExecutorEnum.DEVICE_ISSUE) {
|
||||
const device = await this.deviceService.getDeviceByDeviceUuid(
|
||||
action.entity_id,
|
||||
false,
|
||||
@ -108,12 +110,12 @@ export class SceneService {
|
||||
where: {
|
||||
uuid: unitUuid,
|
||||
spaceType: {
|
||||
type: 'unit',
|
||||
type: SpaceType.UNIT,
|
||||
},
|
||||
},
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
if (!unit || !unit.spaceType || unit.spaceType.type !== 'unit') {
|
||||
if (!unit || !unit.spaceType || unit.spaceType.type !== SpaceType.UNIT) {
|
||||
throw new BadRequestException('Invalid unit UUID');
|
||||
}
|
||||
return {
|
||||
@ -249,7 +251,7 @@ export class SceneService {
|
||||
});
|
||||
|
||||
for (const action of actions) {
|
||||
if (action.actionExecutor === 'device_issue') {
|
||||
if (action.actionExecutor === ActionExecutorEnum.DEVICE_ISSUE) {
|
||||
const device = await this.deviceService.getDeviceByDeviceTuyaUuid(
|
||||
action.entityId,
|
||||
);
|
||||
@ -258,8 +260,8 @@ export class SceneService {
|
||||
action.entityId = device.uuid;
|
||||
}
|
||||
} else if (
|
||||
action.actionExecutor !== 'device_issue' &&
|
||||
action.actionExecutor !== 'delay'
|
||||
action.actionExecutor !== ActionExecutorEnum.DEVICE_ISSUE &&
|
||||
action.actionExecutor !== ActionExecutorEnum.DELAY
|
||||
) {
|
||||
const sceneDetails = await this.getTapToRunSceneDetailsTuya(
|
||||
action.entityId,
|
||||
|
@ -21,10 +21,11 @@ import {
|
||||
} from '../dtos/schedule.dto';
|
||||
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@ApiTags('Schedule Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'schedule',
|
||||
})
|
||||
export class ScheduleController {
|
||||
|
@ -8,10 +8,11 @@ import {
|
||||
import { TimeZoneService } from '../services/timezone.service';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@ApiTags('TimeZone Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'timezone',
|
||||
})
|
||||
export class TimeZoneController {
|
||||
|
@ -23,11 +23,13 @@ import { CheckFloorTypeGuard } from 'src/guards/floor.type.guard';
|
||||
import { CheckUserUnitGuard } from 'src/guards/user.unit.guard';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { UnitPermissionGuard } from 'src/guards/unit.permission.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
|
||||
@ApiTags('Unit Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
path: 'unit',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: SpaceType.UNIT,
|
||||
})
|
||||
export class UnitController {
|
||||
constructor(private readonly unitService: UnitService) {}
|
||||
|
@ -24,6 +24,8 @@ import { UserDevicePermissionService } from 'src/user-device-permission/services
|
||||
import { PermissionType } from '@app/common/constants/permission-type.enum';
|
||||
import { TuyaContext } from '@tuya/tuya-connector-nodejs';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { SpaceType } from '@app/common/constants/space-type.enum';
|
||||
import { CommonErrorCodes } from '@app/common/constants/error-codes.enum';
|
||||
|
||||
@Injectable()
|
||||
export class UnitService {
|
||||
@ -50,7 +52,7 @@ export class UnitService {
|
||||
try {
|
||||
const spaceType = await this.spaceTypeRepository.findOne({
|
||||
where: {
|
||||
type: 'unit',
|
||||
type: SpaceType.UNIT,
|
||||
},
|
||||
});
|
||||
const tuyaUnit = await this.addUnitTuya(addUnitDto.unitName);
|
||||
@ -95,12 +97,12 @@ export class UnitService {
|
||||
where: {
|
||||
uuid: unitUuid,
|
||||
spaceType: {
|
||||
type: 'unit',
|
||||
type: SpaceType.UNIT,
|
||||
},
|
||||
},
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
if (!unit || !unit.spaceType || unit.spaceType.type !== 'unit') {
|
||||
if (!unit || !unit.spaceType || unit.spaceType.type !== SpaceType.UNIT) {
|
||||
throw new BadRequestException('Invalid unit UUID');
|
||||
}
|
||||
return {
|
||||
@ -131,7 +133,11 @@ export class UnitService {
|
||||
relations: ['children', 'spaceType'],
|
||||
});
|
||||
|
||||
if (!space || !space.spaceType || space.spaceType.type !== 'unit') {
|
||||
if (
|
||||
!space ||
|
||||
!space.spaceType ||
|
||||
space.spaceType.type !== SpaceType.UNIT
|
||||
) {
|
||||
throw new BadRequestException('Invalid unit UUID');
|
||||
}
|
||||
|
||||
@ -174,10 +180,10 @@ export class UnitService {
|
||||
return children
|
||||
.filter(
|
||||
(child) =>
|
||||
child.spaceType.type !== 'unit' &&
|
||||
child.spaceType.type !== 'floor' &&
|
||||
child.spaceType.type !== 'community' &&
|
||||
child.spaceType.type !== 'unit',
|
||||
child.spaceType.type !== SpaceType.UNIT &&
|
||||
child.spaceType.type !== SpaceType.FLOOR &&
|
||||
child.spaceType.type !== SpaceType.COMMUNITY &&
|
||||
child.spaceType.type !== SpaceType.UNIT,
|
||||
) // Filter remaining unit and floor and community and unit types
|
||||
.map((child) => ({
|
||||
uuid: child.uuid,
|
||||
@ -190,10 +196,10 @@ export class UnitService {
|
||||
children
|
||||
.filter(
|
||||
(child) =>
|
||||
child.spaceType.type !== 'unit' &&
|
||||
child.spaceType.type !== 'floor' &&
|
||||
child.spaceType.type !== 'community' &&
|
||||
child.spaceType.type !== 'unit',
|
||||
child.spaceType.type !== SpaceType.UNIT &&
|
||||
child.spaceType.type !== SpaceType.FLOOR &&
|
||||
child.spaceType.type !== SpaceType.COMMUNITY &&
|
||||
child.spaceType.type !== SpaceType.UNIT,
|
||||
) // Filter remaining unit and floor and community and unit types
|
||||
.map(async (child) => ({
|
||||
uuid: child.uuid,
|
||||
@ -212,12 +218,12 @@ export class UnitService {
|
||||
where: {
|
||||
uuid: unitUuid,
|
||||
spaceType: {
|
||||
type: 'unit',
|
||||
type: SpaceType.UNIT,
|
||||
},
|
||||
},
|
||||
relations: ['spaceType', 'parent', 'parent.spaceType'],
|
||||
});
|
||||
if (!unit || !unit.spaceType || unit.spaceType.type !== 'unit') {
|
||||
if (!unit || !unit.spaceType || unit.spaceType.type !== SpaceType.UNIT) {
|
||||
throw new BadRequestException('Invalid unit UUID');
|
||||
}
|
||||
return {
|
||||
@ -246,7 +252,7 @@ export class UnitService {
|
||||
relations: ['space', 'space.spaceType'],
|
||||
where: {
|
||||
user: { uuid: userUuid },
|
||||
space: { spaceType: { type: 'unit' } },
|
||||
space: { spaceType: { type: SpaceType.UNIT } },
|
||||
},
|
||||
});
|
||||
|
||||
@ -276,7 +282,7 @@ export class UnitService {
|
||||
space: { uuid: addUserUnitDto.unitUuid },
|
||||
});
|
||||
} catch (err) {
|
||||
if (err.code === '23505') {
|
||||
if (err.code === CommonErrorCodes.DUPLICATE_ENTITY) {
|
||||
throw new HttpException(
|
||||
'User already belongs to this unit',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
@ -298,7 +304,7 @@ export class UnitService {
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
|
||||
if (!unit || !unit.spaceType || unit.spaceType.type !== 'unit') {
|
||||
if (!unit || !unit.spaceType || unit.spaceType.type !== SpaceType.UNIT) {
|
||||
throw new BadRequestException('Invalid unit UUID');
|
||||
}
|
||||
|
||||
@ -383,7 +389,7 @@ export class UnitService {
|
||||
const unit = await this.spaceRepository.findOneOrFail({
|
||||
where: {
|
||||
invitationCode: inviteCode,
|
||||
spaceType: { type: 'unit' },
|
||||
spaceType: { type: SpaceType.UNIT },
|
||||
},
|
||||
relations: ['spaceType'],
|
||||
});
|
||||
|
@ -15,10 +15,11 @@ import { UserDevicePermissionService } from '../services/user-device-permission.
|
||||
import { UserDevicePermissionAddDto } from '../dtos/user-device-permission.add.dto';
|
||||
import { UserDevicePermissionEditDto } from '../dtos/user-device-permission.edit.dto';
|
||||
import { AdminRoleGuard } from 'src/guards/admin.role.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@ApiTags('Device Permission Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'device-permission',
|
||||
})
|
||||
export class UserDevicePermissionController {
|
||||
|
@ -3,6 +3,7 @@ import { UserDevicePermissionAddDto } from '../dtos/user-device-permission.add.d
|
||||
import { UserDevicePermissionEditDto } from '../dtos/user-device-permission.edit.dto';
|
||||
import { DeviceUserPermissionRepository } from '@app/common/modules/device/repositories';
|
||||
import { PermissionTypeRepository } from '@app/common/modules/permission/repositories';
|
||||
import { CommonErrorCodes } from '@app/common/constants/error-codes.enum';
|
||||
|
||||
@Injectable()
|
||||
export class UserDevicePermissionService {
|
||||
@ -24,7 +25,7 @@ export class UserDevicePermissionService {
|
||||
},
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code === '23505') {
|
||||
if (error.code === CommonErrorCodes.DUPLICATE_ENTITY) {
|
||||
throw new HttpException(
|
||||
'This User already belongs to this device',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
@ -54,7 +55,7 @@ export class UserDevicePermissionService {
|
||||
},
|
||||
);
|
||||
} catch (error) {
|
||||
if (error.code === '23505') {
|
||||
if (error.code === CommonErrorCodes.DUPLICATE_ENTITY) {
|
||||
throw new HttpException(
|
||||
'This User already belongs to this device',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
|
@ -17,10 +17,11 @@ import {
|
||||
} from '../dtos/user-notification.dto';
|
||||
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@ApiTags('User Notification Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'user-notification/subscription',
|
||||
})
|
||||
export class UserNotificationController {
|
||||
|
@ -4,6 +4,7 @@ import {
|
||||
UserNotificationUpdateDto,
|
||||
} from '../dtos/user-notification.dto';
|
||||
import { UserNotificationRepository } from '@app/common/modules/user/repositories';
|
||||
import { CommonErrorCodes } from '@app/common/constants/error-codes.enum';
|
||||
|
||||
@Injectable()
|
||||
export class UserNotificationService {
|
||||
@ -20,7 +21,7 @@ export class UserNotificationService {
|
||||
subscriptionUuid: userNotificationAddDto.subscriptionUuid,
|
||||
});
|
||||
} catch (error) {
|
||||
if (error.code === '23505') {
|
||||
if (error.code === CommonErrorCodes.DUPLICATE_ENTITY) {
|
||||
throw new HttpException(
|
||||
'This User already has this subscription uuid',
|
||||
HttpStatus.BAD_REQUEST,
|
||||
|
@ -20,10 +20,11 @@ import {
|
||||
} from '../dtos';
|
||||
import { CheckProfilePictureGuard } from 'src/guards/profile.picture.guard';
|
||||
import { SuperAdminRoleGuard } from 'src/guards/super.admin.role.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@ApiTags('User Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'user',
|
||||
})
|
||||
export class UserController {
|
||||
|
@ -17,10 +17,11 @@ import {
|
||||
AddDoorLockOnlineOneTimeDto,
|
||||
} from '../dtos/temp-pass.dto';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||
|
||||
@ApiTags('Visitor Password Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
version: EnableDisableStatusEnum.ENABLED,
|
||||
path: 'visitor-password',
|
||||
})
|
||||
export class VisitorPasswordController {
|
||||
|
@ -20,6 +20,16 @@ import { PasswordEncryptionService } from 'src/door-lock/services/encryption.ser
|
||||
import { DoorLockService } from 'src/door-lock/services';
|
||||
import { GetDeviceDetailsInterface } from 'src/device/interfaces/get.device.interface';
|
||||
import { DeviceService } from 'src/device/services';
|
||||
import { DeviceStatuses } from '@app/common/constants/device-status.enum';
|
||||
import {
|
||||
DaysEnum,
|
||||
EnableDisableStatusEnum,
|
||||
} from '@app/common/constants/days.enum';
|
||||
import { PasswordType } from '@app/common/constants/password-type.enum';
|
||||
import {
|
||||
CommonHourMinutes,
|
||||
CommonHours,
|
||||
} from '@app/common/constants/hours-minutes.enum';
|
||||
|
||||
@Injectable()
|
||||
export class VisitorPasswordService {
|
||||
@ -67,7 +77,7 @@ export class VisitorPasswordService {
|
||||
const createMultipleOfflinePass =
|
||||
await this.addOfflineTemporaryPasswordTuya(
|
||||
deviceDetails.deviceTuyaUuid,
|
||||
'multiple',
|
||||
PasswordType.MULTIPLE,
|
||||
addDoorLockOfflineMultipleDto,
|
||||
addDoorLockOfflineMultipleDto.passwordName,
|
||||
);
|
||||
@ -117,7 +127,7 @@ export class VisitorPasswordService {
|
||||
const successfulResults = deviceResults
|
||||
.filter(
|
||||
(result) =>
|
||||
result.status === 'fulfilled' &&
|
||||
result.status === DeviceStatuses.FULLFILLED &&
|
||||
(result as PromiseFulfilledResult<any>).value.success,
|
||||
)
|
||||
.map((result) => (result as PromiseFulfilledResult<any>).value);
|
||||
@ -125,11 +135,11 @@ export class VisitorPasswordService {
|
||||
const failedResults = deviceResults
|
||||
.filter(
|
||||
(result) =>
|
||||
result.status === 'rejected' ||
|
||||
result.status === DeviceStatuses.REJECTED ||
|
||||
!(result as PromiseFulfilledResult<any>).value.success,
|
||||
)
|
||||
.map((result) =>
|
||||
result.status === 'rejected'
|
||||
result.status === DeviceStatuses.REJECTED
|
||||
? {
|
||||
success: false,
|
||||
error:
|
||||
@ -238,7 +248,7 @@ export class VisitorPasswordService {
|
||||
const successfulResults = deviceResults
|
||||
.filter(
|
||||
(result) =>
|
||||
result.status === 'fulfilled' &&
|
||||
result.status === DeviceStatuses.FULLFILLED &&
|
||||
(result as PromiseFulfilledResult<any>).value.success,
|
||||
)
|
||||
.map((result) => (result as PromiseFulfilledResult<any>).value);
|
||||
@ -246,11 +256,11 @@ export class VisitorPasswordService {
|
||||
const failedResults = deviceResults
|
||||
.filter(
|
||||
(result) =>
|
||||
result.status === 'rejected' ||
|
||||
result.status === DeviceStatuses.REJECTED ||
|
||||
!(result as PromiseFulfilledResult<any>).value.success,
|
||||
)
|
||||
.map((result) =>
|
||||
result.status === 'rejected'
|
||||
result.status === DeviceStatuses.REJECTED
|
||||
? {
|
||||
success: false,
|
||||
error:
|
||||
@ -298,7 +308,7 @@ export class VisitorPasswordService {
|
||||
method: 'POST',
|
||||
path,
|
||||
body: {
|
||||
...(type === 'multiple' && {
|
||||
...(type === PasswordType.MULTIPLE && {
|
||||
effective_time: addDoorLockOfflineMultipleDto.effectiveTime,
|
||||
invalid_time: addDoorLockOfflineMultipleDto.invalidTime,
|
||||
}),
|
||||
@ -389,7 +399,7 @@ export class VisitorPasswordService {
|
||||
const successfulResults = deviceResults
|
||||
.filter(
|
||||
(result) =>
|
||||
result.status === 'fulfilled' &&
|
||||
result.status === DeviceStatuses.FULLFILLED &&
|
||||
(result as PromiseFulfilledResult<any>).value.success,
|
||||
)
|
||||
.map((result) => (result as PromiseFulfilledResult<any>).value);
|
||||
@ -397,11 +407,11 @@ export class VisitorPasswordService {
|
||||
const failedResults = deviceResults
|
||||
.filter(
|
||||
(result) =>
|
||||
result.status === 'rejected' ||
|
||||
result.status === DeviceStatuses.REJECTED ||
|
||||
!(result as PromiseFulfilledResult<any>).value.success,
|
||||
)
|
||||
.map((result) =>
|
||||
result.status === 'rejected'
|
||||
result.status === DeviceStatuses.REJECTED
|
||||
? {
|
||||
success: false,
|
||||
error:
|
||||
@ -573,7 +583,7 @@ export class VisitorPasswordService {
|
||||
const successfulResults = deviceResults
|
||||
.filter(
|
||||
(result) =>
|
||||
result.status === 'fulfilled' &&
|
||||
result.status === DeviceStatuses.FULLFILLED &&
|
||||
(result as PromiseFulfilledResult<any>).value.success,
|
||||
)
|
||||
.map((result) => (result as PromiseFulfilledResult<any>).value);
|
||||
@ -581,11 +591,11 @@ export class VisitorPasswordService {
|
||||
const failedResults = deviceResults
|
||||
.filter(
|
||||
(result) =>
|
||||
result.status === 'rejected' ||
|
||||
result.status === DeviceStatuses.REJECTED ||
|
||||
!(result as PromiseFulfilledResult<any>).value.success,
|
||||
)
|
||||
.map((result) =>
|
||||
result.status === 'rejected'
|
||||
result.status === DeviceStatuses.REJECTED
|
||||
? {
|
||||
success: false,
|
||||
error:
|
||||
@ -707,7 +717,7 @@ export class VisitorPasswordService {
|
||||
schedule_list: scheduleList,
|
||||
}),
|
||||
|
||||
type: '0',
|
||||
type: EnableDisableStatusEnum.DISABLED,
|
||||
},
|
||||
});
|
||||
|
||||
@ -722,7 +732,15 @@ export class VisitorPasswordService {
|
||||
|
||||
getWorkingDayValue(days) {
|
||||
// Array representing the days of the week
|
||||
const weekDays = ['Sat', 'Fri', 'Thu', 'Wed', 'Tue', 'Mon', 'Sun'];
|
||||
const weekDays = [
|
||||
DaysEnum.SAT,
|
||||
DaysEnum.FRI,
|
||||
DaysEnum.THU,
|
||||
DaysEnum.WED,
|
||||
DaysEnum.TUE,
|
||||
DaysEnum.MON,
|
||||
DaysEnum.SUN,
|
||||
];
|
||||
|
||||
// Initialize a binary string with 7 bits
|
||||
let binaryString = '0000000';
|
||||
@ -731,10 +749,10 @@ export class VisitorPasswordService {
|
||||
days.forEach((day) => {
|
||||
const index = weekDays.indexOf(day);
|
||||
if (index !== -1) {
|
||||
// Set the corresponding bit to '1'
|
||||
// Set the corresponding bit to EnableDisableStatusEnum.ENABLED
|
||||
binaryString =
|
||||
binaryString.substring(0, index) +
|
||||
'1' +
|
||||
EnableDisableStatusEnum.ENABLED +
|
||||
binaryString.substring(index + 1);
|
||||
}
|
||||
});
|
||||
@ -746,17 +764,27 @@ export class VisitorPasswordService {
|
||||
}
|
||||
getDaysFromWorkingDayValue(workingDayValue) {
|
||||
// Array representing the days of the week
|
||||
const weekDays = ['Sat', 'Fri', 'Thu', 'Wed', 'Tue', 'Mon', 'Sun'];
|
||||
const weekDays = [
|
||||
DaysEnum.SAT,
|
||||
DaysEnum.FRI,
|
||||
DaysEnum.THU,
|
||||
DaysEnum.WED,
|
||||
DaysEnum.TUE,
|
||||
DaysEnum.MON,
|
||||
DaysEnum.SUN,
|
||||
];
|
||||
|
||||
// Convert the integer to a binary string and pad with leading zeros to ensure 7 bits
|
||||
const binaryString = workingDayValue.toString(2).padStart(7, '0');
|
||||
const binaryString = workingDayValue
|
||||
.toString(2)
|
||||
.padStart(7, EnableDisableStatusEnum.DISABLED);
|
||||
|
||||
// Initialize an array to hold the days of the week
|
||||
const days = [];
|
||||
|
||||
// Iterate through the binary string and weekDays array
|
||||
for (let i = 0; i < binaryString.length; i++) {
|
||||
if (binaryString[i] === '1') {
|
||||
if (binaryString[i] === EnableDisableStatusEnum.ENABLED) {
|
||||
days.push(weekDays[i]);
|
||||
}
|
||||
}
|
||||
@ -766,8 +794,8 @@ export class VisitorPasswordService {
|
||||
timeToMinutes(timeStr) {
|
||||
try {
|
||||
// Special case for "24:00"
|
||||
if (timeStr === '24:00') {
|
||||
return 1440;
|
||||
if (timeStr === CommonHours.TWENTY_FOUR) {
|
||||
return CommonHourMinutes.TWENTY_FOUR;
|
||||
}
|
||||
|
||||
// Regular expression to validate the 24-hour time format (HH:MM)
|
||||
@ -795,20 +823,26 @@ export class VisitorPasswordService {
|
||||
if (
|
||||
typeof totalMinutes !== 'number' ||
|
||||
totalMinutes < 0 ||
|
||||
totalMinutes > 1440
|
||||
totalMinutes > CommonHourMinutes.TWENTY_FOUR
|
||||
) {
|
||||
throw new Error('Invalid minutes value');
|
||||
}
|
||||
|
||||
if (totalMinutes === 1440) {
|
||||
return '24:00';
|
||||
if (totalMinutes === CommonHourMinutes.TWENTY_FOUR) {
|
||||
return CommonHours.TWENTY_FOUR;
|
||||
}
|
||||
|
||||
const hours = Math.floor(totalMinutes / 60);
|
||||
const minutes = totalMinutes % 60;
|
||||
|
||||
const formattedHours = String(hours).padStart(2, '0');
|
||||
const formattedMinutes = String(minutes).padStart(2, '0');
|
||||
const formattedHours = String(hours).padStart(
|
||||
2,
|
||||
EnableDisableStatusEnum.DISABLED,
|
||||
);
|
||||
const formattedMinutes = String(minutes).padStart(
|
||||
2,
|
||||
EnableDisableStatusEnum.DISABLED,
|
||||
);
|
||||
|
||||
return `${formattedHours}:${formattedMinutes}`;
|
||||
} catch (error) {
|
||||
@ -846,7 +880,7 @@ export class VisitorPasswordService {
|
||||
invalid_time: addDeviceObj.invalidTime,
|
||||
password_type: 'ticket',
|
||||
ticket_id: addDeviceObj.ticketId,
|
||||
type: '1',
|
||||
type: EnableDisableStatusEnum.ENABLED,
|
||||
},
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user