mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-11 15:48:09 +00:00
Compare commits
6 Commits
refactor/a
...
0b9eef276e
Author | SHA1 | Date | |
---|---|---|---|
0b9eef276e | |||
b3f8b92826 | |||
5d4e5ca87e | |||
f4e748d735 | |||
f4f7999ae0 | |||
82c82d521c |
@ -3,6 +3,7 @@ import * as fs from 'fs';
|
|||||||
|
|
||||||
import { ProjectParam } from '@app/common/dto/project-param.dto';
|
import { ProjectParam } from '@app/common/dto/project-param.dto';
|
||||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||||
|
import { DeviceStatusFirebaseService } from '@app/common/firebase/devices-status/services/devices-status.service';
|
||||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||||
import { CommunityRepository } from '@app/common/modules/community/repositories';
|
import { CommunityRepository } from '@app/common/modules/community/repositories';
|
||||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||||
@ -20,6 +21,7 @@ export class DeviceCommissionService {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly tuyaService: TuyaService,
|
private readonly tuyaService: TuyaService,
|
||||||
private readonly deviceService: DeviceService,
|
private readonly deviceService: DeviceService,
|
||||||
|
private readonly deviceStatusFirebaseService: DeviceStatusFirebaseService,
|
||||||
private readonly communityRepository: CommunityRepository,
|
private readonly communityRepository: CommunityRepository,
|
||||||
private readonly spaceRepository: SpaceRepository,
|
private readonly spaceRepository: SpaceRepository,
|
||||||
private readonly subspaceRepository: SubspaceRepository,
|
private readonly subspaceRepository: SubspaceRepository,
|
||||||
@ -209,6 +211,10 @@ export class DeviceCommissionService {
|
|||||||
rawDeviceId,
|
rawDeviceId,
|
||||||
tuyaSpaceId,
|
tuyaSpaceId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
await this.deviceStatusFirebaseService.addDeviceStatusByDeviceUuid(
|
||||||
|
rawDeviceId,
|
||||||
|
);
|
||||||
successCount.value++;
|
successCount.value++;
|
||||||
console.log(
|
console.log(
|
||||||
`Device ${rawDeviceId} successfully processed and transferred to Tuya space ${tuyaSpaceId}`,
|
`Device ${rawDeviceId} successfully processed and transferred to Tuya space ${tuyaSpaceId}`,
|
||||||
|
@ -111,6 +111,7 @@ export class InviteUserService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const invitedUser = await queryRunner.manager.save(inviteUser);
|
const invitedUser = await queryRunner.manager.save(inviteUser);
|
||||||
|
const invitedRoleType = await this.getRoleTypeByUuid(roleUuid);
|
||||||
|
|
||||||
// Link user to spaces
|
// Link user to spaces
|
||||||
const spacePromises = validSpaces.map(async (space) => {
|
const spacePromises = validSpaces.map(async (space) => {
|
||||||
@ -128,7 +129,7 @@ export class InviteUserService {
|
|||||||
await this.emailService.sendEmailWithInvitationTemplate(email, {
|
await this.emailService.sendEmailWithInvitationTemplate(email, {
|
||||||
name: firstName,
|
name: firstName,
|
||||||
invitationCode,
|
invitationCode,
|
||||||
role: roleType,
|
role: invitedRoleType.replace(/_/g, ' '),
|
||||||
spacesList: spaceNames,
|
spacesList: spaceNames,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -96,6 +96,16 @@ export class ScheduleService {
|
|||||||
throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND);
|
throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
deviceDetails.productDevice.prodType == ProductType.CUR_2 &&
|
||||||
|
addScheduleDto.category != 'Timer'
|
||||||
|
) {
|
||||||
|
throw new HttpException(
|
||||||
|
'Invalid category for CUR_2 devices',
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
this.ensureProductTypeSupportedForSchedule(
|
this.ensureProductTypeSupportedForSchedule(
|
||||||
deviceDetails.productDevice.prodType as ProductType,
|
deviceDetails.productDevice.prodType as ProductType,
|
||||||
);
|
);
|
||||||
@ -103,6 +113,7 @@ export class ScheduleService {
|
|||||||
await this.addScheduleDeviceInTuya(
|
await this.addScheduleDeviceInTuya(
|
||||||
deviceDetails.deviceTuyaUuid,
|
deviceDetails.deviceTuyaUuid,
|
||||||
addScheduleDto,
|
addScheduleDto,
|
||||||
|
deviceDetails.productDevice.prodType as ProductType,
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
@ -125,10 +136,14 @@ export class ScheduleService {
|
|||||||
const schedules = await this.getScheduleDeviceInTuya(
|
const schedules = await this.getScheduleDeviceInTuya(
|
||||||
deviceDetails.deviceTuyaUuid,
|
deviceDetails.deviceTuyaUuid,
|
||||||
category,
|
category,
|
||||||
|
deviceDetails.productDevice.prodType as ProductType,
|
||||||
);
|
);
|
||||||
const result = schedules.result.map((schedule: any) => {
|
const result = schedules.result.map((schedule: any) => {
|
||||||
return {
|
return {
|
||||||
category: schedule.category.replace('category_', ''),
|
category:
|
||||||
|
deviceDetails.productDevice.prodType == ProductType.CUR_2
|
||||||
|
? schedule.category
|
||||||
|
: schedule.category.replace('category_', ''),
|
||||||
enable: schedule.enable,
|
enable: schedule.enable,
|
||||||
function: {
|
function: {
|
||||||
code: schedule.functions[0].code,
|
code: schedule.functions[0].code,
|
||||||
@ -159,6 +174,16 @@ export class ScheduleService {
|
|||||||
throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND);
|
throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
deviceDetails.productDevice.prodType == ProductType.CUR_2 &&
|
||||||
|
updateScheduleDto.category != 'Timer'
|
||||||
|
) {
|
||||||
|
throw new HttpException(
|
||||||
|
'Invalid category for CUR_2 devices',
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Corrected condition for supported device types
|
// Corrected condition for supported device types
|
||||||
this.ensureProductTypeSupportedForSchedule(
|
this.ensureProductTypeSupportedForSchedule(
|
||||||
deviceDetails.productDevice.prodType as ProductType,
|
deviceDetails.productDevice.prodType as ProductType,
|
||||||
@ -167,6 +192,7 @@ export class ScheduleService {
|
|||||||
await this.updateScheduleDeviceInTuya(
|
await this.updateScheduleDeviceInTuya(
|
||||||
deviceDetails.deviceTuyaUuid,
|
deviceDetails.deviceTuyaUuid,
|
||||||
updateScheduleDto,
|
updateScheduleDto,
|
||||||
|
deviceDetails.productDevice.prodType as ProductType,
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
@ -192,6 +218,7 @@ export class ScheduleService {
|
|||||||
private async addScheduleDeviceInTuya(
|
private async addScheduleDeviceInTuya(
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
addScheduleDto: AddScheduleDto,
|
addScheduleDto: AddScheduleDto,
|
||||||
|
deviceType: ProductType,
|
||||||
): Promise<addScheduleDeviceInterface> {
|
): Promise<addScheduleDeviceInterface> {
|
||||||
try {
|
try {
|
||||||
const convertedTime = convertTimestampToDubaiTime(addScheduleDto.time);
|
const convertedTime = convertTimestampToDubaiTime(addScheduleDto.time);
|
||||||
@ -210,7 +237,10 @@ export class ScheduleService {
|
|||||||
...addScheduleDto.function,
|
...addScheduleDto.function,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
category: `category_${addScheduleDto.category}`,
|
category:
|
||||||
|
deviceType == ProductType.CUR_2
|
||||||
|
? addScheduleDto.category
|
||||||
|
: `category_${addScheduleDto.category}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -226,9 +256,12 @@ export class ScheduleService {
|
|||||||
private async getScheduleDeviceInTuya(
|
private async getScheduleDeviceInTuya(
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
category: string,
|
category: string,
|
||||||
|
deviceType: ProductType,
|
||||||
): Promise<getDeviceScheduleInterface> {
|
): Promise<getDeviceScheduleInterface> {
|
||||||
try {
|
try {
|
||||||
const path = `/v2.0/cloud/timer/device/${deviceId}?category=category_${category}`;
|
const categoryToSent =
|
||||||
|
deviceType == ProductType.CUR_2 ? category : `category_${category}`;
|
||||||
|
const path = `/v2.0/cloud/timer/device/${deviceId}?category=${categoryToSent}`;
|
||||||
const response = await this.tuya.request({
|
const response = await this.tuya.request({
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
path,
|
path,
|
||||||
@ -248,6 +281,7 @@ export class ScheduleService {
|
|||||||
private async updateScheduleDeviceInTuya(
|
private async updateScheduleDeviceInTuya(
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
updateScheduleDto: UpdateScheduleDto,
|
updateScheduleDto: UpdateScheduleDto,
|
||||||
|
deviceType: ProductType,
|
||||||
): Promise<addScheduleDeviceInterface> {
|
): Promise<addScheduleDeviceInterface> {
|
||||||
try {
|
try {
|
||||||
const convertedTime = convertTimestampToDubaiTime(updateScheduleDto.time);
|
const convertedTime = convertTimestampToDubaiTime(updateScheduleDto.time);
|
||||||
@ -268,7 +302,10 @@ export class ScheduleService {
|
|||||||
value: updateScheduleDto.function.value,
|
value: updateScheduleDto.function.value,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
category: `category_${updateScheduleDto.category}`,
|
category:
|
||||||
|
deviceType == ProductType.CUR_2
|
||||||
|
? updateScheduleDto.category
|
||||||
|
: `category_${updateScheduleDto.category}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,39 +1,39 @@
|
|||||||
import { VisitorPasswordRepository } from './../../../libs/common/src/modules/visitor-password/repositories/visitor-password.repository';
|
import { ProductType } from '@app/common/constants/product-type.enum';
|
||||||
|
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||||
import {
|
import {
|
||||||
Injectable,
|
BadRequestException,
|
||||||
HttpException,
|
HttpException,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
BadRequestException,
|
Injectable,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { TuyaContext } from '@tuya/tuya-connector-nodejs';
|
|
||||||
import { ConfigService } from '@nestjs/config';
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import { TuyaContext } from '@tuya/tuya-connector-nodejs';
|
||||||
import {
|
import {
|
||||||
addDeviceObjectInterface,
|
addDeviceObjectInterface,
|
||||||
createTickInterface,
|
createTickInterface,
|
||||||
} from '../interfaces/visitor-password.interface';
|
} from '../interfaces/visitor-password.interface';
|
||||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
import { VisitorPasswordRepository } from './../../../libs/common/src/modules/visitor-password/repositories/visitor-password.repository';
|
||||||
import { ProductType } from '@app/common/constants/product-type.enum';
|
|
||||||
|
|
||||||
import { AddDoorLockTemporaryPasswordDto } from '../dtos';
|
|
||||||
import { EmailService } from '@app/common/util/email.service';
|
|
||||||
import { PasswordEncryptionService } from 'src/door-lock/services/encryption.services';
|
|
||||||
import { DoorLockService } from 'src/door-lock/services';
|
|
||||||
import { DeviceService } from 'src/device/services';
|
|
||||||
import { DeviceStatuses } from '@app/common/constants/device-status.enum';
|
|
||||||
import {
|
import {
|
||||||
DaysEnum,
|
DaysEnum,
|
||||||
EnableDisableStatusEnum,
|
EnableDisableStatusEnum,
|
||||||
} from '@app/common/constants/days.enum';
|
} from '@app/common/constants/days.enum';
|
||||||
import { PasswordType } from '@app/common/constants/password-type.enum';
|
import { DeviceStatuses } from '@app/common/constants/device-status.enum';
|
||||||
import {
|
import {
|
||||||
CommonHourMinutes,
|
CommonHourMinutes,
|
||||||
CommonHours,
|
CommonHours,
|
||||||
} from '@app/common/constants/hours-minutes.enum';
|
} from '@app/common/constants/hours-minutes.enum';
|
||||||
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
import { ORPHAN_SPACE_NAME } from '@app/common/constants/orphan-constant';
|
||||||
|
import { PasswordType } from '@app/common/constants/password-type.enum';
|
||||||
import { VisitorPasswordEnum } from '@app/common/constants/visitor-password.enum';
|
import { VisitorPasswordEnum } from '@app/common/constants/visitor-password.enum';
|
||||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||||
|
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||||
|
import { EmailService } from '@app/common/util/email.service';
|
||||||
|
import { DeviceService } from 'src/device/services';
|
||||||
|
import { DoorLockService } from 'src/door-lock/services';
|
||||||
|
import { PasswordEncryptionService } from 'src/door-lock/services/encryption.services';
|
||||||
import { Not } from 'typeorm';
|
import { Not } from 'typeorm';
|
||||||
import { ORPHAN_SPACE_NAME } from '@app/common/constants/orphan-constant';
|
import { AddDoorLockTemporaryPasswordDto } from '../dtos';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VisitorPasswordService {
|
export class VisitorPasswordService {
|
||||||
@ -57,6 +57,67 @@ export class VisitorPasswordService {
|
|||||||
secretKey,
|
secretKey,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async getPasswords(projectUuid: string) {
|
||||||
|
await this.validateProject(projectUuid);
|
||||||
|
|
||||||
|
const deviceIds = await this.deviceRepository.find({
|
||||||
|
where: {
|
||||||
|
productDevice: {
|
||||||
|
prodType: ProductType.DL,
|
||||||
|
},
|
||||||
|
spaceDevice: {
|
||||||
|
spaceName: Not(ORPHAN_SPACE_NAME),
|
||||||
|
community: {
|
||||||
|
project: {
|
||||||
|
uuid: projectUuid,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = [];
|
||||||
|
deviceIds.forEach((deviceId) => {
|
||||||
|
data.push(
|
||||||
|
this.doorLockService
|
||||||
|
.getOnlineTemporaryPasswordsOneTime(deviceId.uuid, true, false)
|
||||||
|
.catch(() => {}),
|
||||||
|
this.doorLockService
|
||||||
|
.getOnlineTemporaryPasswordsOneTime(deviceId.uuid, true, true)
|
||||||
|
.catch(() => {}),
|
||||||
|
this.doorLockService
|
||||||
|
.getOnlineTemporaryPasswordsMultiple(deviceId.uuid, true, false)
|
||||||
|
.catch(() => {}),
|
||||||
|
this.doorLockService
|
||||||
|
.getOnlineTemporaryPasswordsMultiple(deviceId.uuid, true, true)
|
||||||
|
.catch(() => {}),
|
||||||
|
this.doorLockService
|
||||||
|
.getOfflineOneTimeTemporaryPasswords(deviceId.uuid, true, false)
|
||||||
|
.catch(() => {}),
|
||||||
|
this.doorLockService
|
||||||
|
.getOfflineOneTimeTemporaryPasswords(deviceId.uuid, true, true)
|
||||||
|
.catch(() => {}),
|
||||||
|
this.doorLockService
|
||||||
|
.getOfflineMultipleTimeTemporaryPasswords(deviceId.uuid, true, false)
|
||||||
|
.catch(() => {}),
|
||||||
|
this.doorLockService
|
||||||
|
.getOfflineMultipleTimeTemporaryPasswords(deviceId.uuid, true, true)
|
||||||
|
.catch(() => {}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
const result = (await Promise.all(data)).flat().filter((datum) => {
|
||||||
|
return datum != null;
|
||||||
|
});
|
||||||
|
|
||||||
|
return new SuccessResponseDto({
|
||||||
|
message: 'Successfully retrieved temporary passwords',
|
||||||
|
data: result,
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
async handleTemporaryPassword(
|
async handleTemporaryPassword(
|
||||||
addDoorLockTemporaryPasswordDto: AddDoorLockTemporaryPasswordDto,
|
addDoorLockTemporaryPasswordDto: AddDoorLockTemporaryPasswordDto,
|
||||||
userUuid: string,
|
userUuid: string,
|
||||||
@ -105,7 +166,7 @@ export class VisitorPasswordService {
|
|||||||
statusCode: HttpStatus.CREATED,
|
statusCode: HttpStatus.CREATED,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async addOfflineMultipleTimeTemporaryPassword(
|
private async addOfflineMultipleTimeTemporaryPassword(
|
||||||
addDoorLockOfflineMultipleDto: AddDoorLockTemporaryPasswordDto,
|
addDoorLockOfflineMultipleDto: AddDoorLockTemporaryPasswordDto,
|
||||||
userUuid: string,
|
userUuid: string,
|
||||||
projectUuid: string,
|
projectUuid: string,
|
||||||
@ -169,6 +230,7 @@ export class VisitorPasswordService {
|
|||||||
success: true,
|
success: true,
|
||||||
result: createMultipleOfflinePass.result,
|
result: createMultipleOfflinePass.result,
|
||||||
deviceUuid,
|
deviceUuid,
|
||||||
|
deviceName: deviceDetails.name,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
@ -231,7 +293,7 @@ export class VisitorPasswordService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async addOfflineOneTimeTemporaryPassword(
|
private async addOfflineOneTimeTemporaryPassword(
|
||||||
addDoorLockOfflineOneTimeDto: AddDoorLockTemporaryPasswordDto,
|
addDoorLockOfflineOneTimeDto: AddDoorLockTemporaryPasswordDto,
|
||||||
userUuid: string,
|
userUuid: string,
|
||||||
projectUuid: string,
|
projectUuid: string,
|
||||||
@ -295,6 +357,7 @@ export class VisitorPasswordService {
|
|||||||
success: true,
|
success: true,
|
||||||
result: createOnceOfflinePass.result,
|
result: createOnceOfflinePass.result,
|
||||||
deviceUuid,
|
deviceUuid,
|
||||||
|
deviceName: deviceDetails.name,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
@ -357,7 +420,7 @@ export class VisitorPasswordService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async addOfflineTemporaryPasswordTuya(
|
private async addOfflineTemporaryPasswordTuya(
|
||||||
doorLockUuid: string,
|
doorLockUuid: string,
|
||||||
type: string,
|
type: string,
|
||||||
addDoorLockOfflineMultipleDto: AddDoorLockTemporaryPasswordDto,
|
addDoorLockOfflineMultipleDto: AddDoorLockTemporaryPasswordDto,
|
||||||
@ -387,7 +450,7 @@ export class VisitorPasswordService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async addOnlineTemporaryPasswordMultipleTime(
|
private async addOnlineTemporaryPasswordMultipleTime(
|
||||||
addDoorLockOnlineMultipleDto: AddDoorLockTemporaryPasswordDto,
|
addDoorLockOnlineMultipleDto: AddDoorLockTemporaryPasswordDto,
|
||||||
userUuid: string,
|
userUuid: string,
|
||||||
projectUuid: string,
|
projectUuid: string,
|
||||||
@ -448,6 +511,7 @@ export class VisitorPasswordService {
|
|||||||
success: true,
|
success: true,
|
||||||
id: createPass.result.id,
|
id: createPass.result.id,
|
||||||
deviceUuid,
|
deviceUuid,
|
||||||
|
deviceName: passwordData.deviceName,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
@ -508,67 +572,8 @@ export class VisitorPasswordService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async getPasswords(projectUuid: string) {
|
|
||||||
await this.validateProject(projectUuid);
|
|
||||||
|
|
||||||
const deviceIds = await this.deviceRepository.find({
|
private async addOnlineTemporaryPasswordOneTime(
|
||||||
where: {
|
|
||||||
productDevice: {
|
|
||||||
prodType: ProductType.DL,
|
|
||||||
},
|
|
||||||
spaceDevice: {
|
|
||||||
spaceName: Not(ORPHAN_SPACE_NAME),
|
|
||||||
community: {
|
|
||||||
project: {
|
|
||||||
uuid: projectUuid,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
isActive: true,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const data = [];
|
|
||||||
deviceIds.forEach((deviceId) => {
|
|
||||||
data.push(
|
|
||||||
this.doorLockService
|
|
||||||
.getOnlineTemporaryPasswordsOneTime(deviceId.uuid, true, false)
|
|
||||||
.catch(() => {}),
|
|
||||||
this.doorLockService
|
|
||||||
.getOnlineTemporaryPasswordsOneTime(deviceId.uuid, true, true)
|
|
||||||
.catch(() => {}),
|
|
||||||
this.doorLockService
|
|
||||||
.getOnlineTemporaryPasswordsMultiple(deviceId.uuid, true, false)
|
|
||||||
.catch(() => {}),
|
|
||||||
this.doorLockService
|
|
||||||
.getOnlineTemporaryPasswordsMultiple(deviceId.uuid, true, true)
|
|
||||||
.catch(() => {}),
|
|
||||||
this.doorLockService
|
|
||||||
.getOfflineOneTimeTemporaryPasswords(deviceId.uuid, true, false)
|
|
||||||
.catch(() => {}),
|
|
||||||
this.doorLockService
|
|
||||||
.getOfflineOneTimeTemporaryPasswords(deviceId.uuid, true, true)
|
|
||||||
.catch(() => {}),
|
|
||||||
this.doorLockService
|
|
||||||
.getOfflineMultipleTimeTemporaryPasswords(deviceId.uuid, true, false)
|
|
||||||
.catch(() => {}),
|
|
||||||
this.doorLockService
|
|
||||||
.getOfflineMultipleTimeTemporaryPasswords(deviceId.uuid, true, true)
|
|
||||||
.catch(() => {}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
const result = (await Promise.all(data)).flat().filter((datum) => {
|
|
||||||
return datum != null;
|
|
||||||
});
|
|
||||||
|
|
||||||
return new SuccessResponseDto({
|
|
||||||
message: 'Successfully retrieved temporary passwords',
|
|
||||||
data: result,
|
|
||||||
statusCode: HttpStatus.OK,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async addOnlineTemporaryPasswordOneTime(
|
|
||||||
addDoorLockOnlineOneTimeDto: AddDoorLockTemporaryPasswordDto,
|
addDoorLockOnlineOneTimeDto: AddDoorLockTemporaryPasswordDto,
|
||||||
userUuid: string,
|
userUuid: string,
|
||||||
projectUuid: string,
|
projectUuid: string,
|
||||||
@ -627,6 +632,7 @@ export class VisitorPasswordService {
|
|||||||
return {
|
return {
|
||||||
success: true,
|
success: true,
|
||||||
id: createPass.result.id,
|
id: createPass.result.id,
|
||||||
|
deviceName: passwordData.deviceName,
|
||||||
deviceUuid,
|
deviceUuid,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -688,7 +694,7 @@ export class VisitorPasswordService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async getTicketAndEncryptedPassword(
|
private async getTicketAndEncryptedPassword(
|
||||||
doorLockUuid: string,
|
doorLockUuid: string,
|
||||||
passwordPlan: string,
|
passwordPlan: string,
|
||||||
projectUuid: string,
|
projectUuid: string,
|
||||||
@ -725,6 +731,7 @@ export class VisitorPasswordService {
|
|||||||
ticketKey: ticketDetails.result.ticket_key,
|
ticketKey: ticketDetails.result.ticket_key,
|
||||||
encryptedPassword: decrypted,
|
encryptedPassword: decrypted,
|
||||||
deviceTuyaUuid: deviceDetails.deviceTuyaUuid,
|
deviceTuyaUuid: deviceDetails.deviceTuyaUuid,
|
||||||
|
deviceName: deviceDetails.name,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
@ -734,7 +741,7 @@ export class VisitorPasswordService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async createDoorLockTicketTuya(
|
private async createDoorLockTicketTuya(
|
||||||
deviceUuid: string,
|
deviceUuid: string,
|
||||||
): Promise<createTickInterface> {
|
): Promise<createTickInterface> {
|
||||||
try {
|
try {
|
||||||
@ -753,7 +760,7 @@ export class VisitorPasswordService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async addOnlineTemporaryPasswordMultipleTuya(
|
private async addOnlineTemporaryPasswordMultipleTuya(
|
||||||
addDeviceObj: addDeviceObjectInterface,
|
addDeviceObj: addDeviceObjectInterface,
|
||||||
doorLockUuid: string,
|
doorLockUuid: string,
|
||||||
): Promise<createTickInterface> {
|
): Promise<createTickInterface> {
|
||||||
@ -795,7 +802,7 @@ export class VisitorPasswordService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
getWorkingDayValue(days) {
|
private getWorkingDayValue(days) {
|
||||||
// Array representing the days of the week
|
// Array representing the days of the week
|
||||||
const weekDays = [
|
const weekDays = [
|
||||||
DaysEnum.SAT,
|
DaysEnum.SAT,
|
||||||
@ -827,36 +834,7 @@ export class VisitorPasswordService {
|
|||||||
|
|
||||||
return workingDayValue;
|
return workingDayValue;
|
||||||
}
|
}
|
||||||
getDaysFromWorkingDayValue(workingDayValue) {
|
private timeToMinutes(timeStr) {
|
||||||
// Array representing the days of the week
|
|
||||||
const weekDays = [
|
|
||||||
DaysEnum.SAT,
|
|
||||||
DaysEnum.FRI,
|
|
||||||
DaysEnum.THU,
|
|
||||||
DaysEnum.WED,
|
|
||||||
DaysEnum.TUE,
|
|
||||||
DaysEnum.MON,
|
|
||||||
DaysEnum.SUN,
|
|
||||||
];
|
|
||||||
|
|
||||||
// Convert the integer to a binary string and pad with leading zeros to ensure 7 bits
|
|
||||||
const binaryString = workingDayValue
|
|
||||||
.toString(2)
|
|
||||||
.padStart(7, EnableDisableStatusEnum.DISABLED);
|
|
||||||
|
|
||||||
// Initialize an array to hold the days of the week
|
|
||||||
const days = [];
|
|
||||||
|
|
||||||
// Iterate through the binary string and weekDays array
|
|
||||||
for (let i = 0; i < binaryString.length; i++) {
|
|
||||||
if (binaryString[i] === EnableDisableStatusEnum.ENABLED) {
|
|
||||||
days.push(weekDays[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return days;
|
|
||||||
}
|
|
||||||
timeToMinutes(timeStr) {
|
|
||||||
try {
|
try {
|
||||||
// Special case for "24:00"
|
// Special case for "24:00"
|
||||||
if (timeStr === CommonHours.TWENTY_FOUR) {
|
if (timeStr === CommonHours.TWENTY_FOUR) {
|
||||||
@ -883,38 +861,7 @@ export class VisitorPasswordService {
|
|||||||
throw new HttpException(error.message, HttpStatus.INTERNAL_SERVER_ERROR);
|
throw new HttpException(error.message, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
minutesToTime(totalMinutes) {
|
private async getDeviceByDeviceUuid(
|
||||||
try {
|
|
||||||
if (
|
|
||||||
typeof totalMinutes !== 'number' ||
|
|
||||||
totalMinutes < 0 ||
|
|
||||||
totalMinutes > CommonHourMinutes.TWENTY_FOUR
|
|
||||||
) {
|
|
||||||
throw new Error('Invalid minutes value');
|
|
||||||
}
|
|
||||||
|
|
||||||
if (totalMinutes === CommonHourMinutes.TWENTY_FOUR) {
|
|
||||||
return CommonHours.TWENTY_FOUR;
|
|
||||||
}
|
|
||||||
|
|
||||||
const hours = Math.floor(totalMinutes / 60);
|
|
||||||
const minutes = totalMinutes % 60;
|
|
||||||
|
|
||||||
const formattedHours = String(hours).padStart(
|
|
||||||
2,
|
|
||||||
EnableDisableStatusEnum.DISABLED,
|
|
||||||
);
|
|
||||||
const formattedMinutes = String(minutes).padStart(
|
|
||||||
2,
|
|
||||||
EnableDisableStatusEnum.DISABLED,
|
|
||||||
);
|
|
||||||
|
|
||||||
return `${formattedHours}:${formattedMinutes}`;
|
|
||||||
} catch (error) {
|
|
||||||
throw new HttpException(error.message, HttpStatus.INTERNAL_SERVER_ERROR);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async getDeviceByDeviceUuid(
|
|
||||||
deviceUuid: string,
|
deviceUuid: string,
|
||||||
withProductDevice: boolean = true,
|
withProductDevice: boolean = true,
|
||||||
projectUuid: string,
|
projectUuid: string,
|
||||||
@ -939,7 +886,7 @@ export class VisitorPasswordService {
|
|||||||
throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND);
|
throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async addOnlineTemporaryPasswordOneTimeTuya(
|
private async addOnlineTemporaryPasswordOneTimeTuya(
|
||||||
addDeviceObj: addDeviceObjectInterface,
|
addDeviceObj: addDeviceObjectInterface,
|
||||||
doorLockUuid: string,
|
doorLockUuid: string,
|
||||||
): Promise<createTickInterface> {
|
): Promise<createTickInterface> {
|
||||||
|
Reference in New Issue
Block a user