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