mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
Compare commits
1 Commits
0b9eef276e
...
refactor/a
Author | SHA1 | Date | |
---|---|---|---|
7ea53feddc |
@ -3,7 +3,6 @@ import * as fs from 'fs';
|
||||
|
||||
import { ProjectParam } from '@app/common/dto/project-param.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 { CommunityRepository } from '@app/common/modules/community/repositories';
|
||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||
@ -21,7 +20,6 @@ export class DeviceCommissionService {
|
||||
constructor(
|
||||
private readonly tuyaService: TuyaService,
|
||||
private readonly deviceService: DeviceService,
|
||||
private readonly deviceStatusFirebaseService: DeviceStatusFirebaseService,
|
||||
private readonly communityRepository: CommunityRepository,
|
||||
private readonly spaceRepository: SpaceRepository,
|
||||
private readonly subspaceRepository: SubspaceRepository,
|
||||
@ -211,10 +209,6 @@ export class DeviceCommissionService {
|
||||
rawDeviceId,
|
||||
tuyaSpaceId,
|
||||
);
|
||||
|
||||
await this.deviceStatusFirebaseService.addDeviceStatusByDeviceUuid(
|
||||
rawDeviceId,
|
||||
);
|
||||
successCount.value++;
|
||||
console.log(
|
||||
`Device ${rawDeviceId} successfully processed and transferred to Tuya space ${tuyaSpaceId}`,
|
||||
|
@ -111,7 +111,6 @@ export class InviteUserService {
|
||||
});
|
||||
|
||||
const invitedUser = await queryRunner.manager.save(inviteUser);
|
||||
const invitedRoleType = await this.getRoleTypeByUuid(roleUuid);
|
||||
|
||||
// Link user to spaces
|
||||
const spacePromises = validSpaces.map(async (space) => {
|
||||
@ -129,7 +128,7 @@ export class InviteUserService {
|
||||
await this.emailService.sendEmailWithInvitationTemplate(email, {
|
||||
name: firstName,
|
||||
invitationCode,
|
||||
role: invitedRoleType.replace(/_/g, ' '),
|
||||
role: roleType,
|
||||
spacesList: spaceNames,
|
||||
});
|
||||
|
||||
|
@ -96,16 +96,6 @@ export class ScheduleService {
|
||||
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(
|
||||
deviceDetails.productDevice.prodType as ProductType,
|
||||
);
|
||||
@ -113,7 +103,6 @@ export class ScheduleService {
|
||||
await this.addScheduleDeviceInTuya(
|
||||
deviceDetails.deviceTuyaUuid,
|
||||
addScheduleDto,
|
||||
deviceDetails.productDevice.prodType as ProductType,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
@ -136,14 +125,10 @@ export class ScheduleService {
|
||||
const schedules = await this.getScheduleDeviceInTuya(
|
||||
deviceDetails.deviceTuyaUuid,
|
||||
category,
|
||||
deviceDetails.productDevice.prodType as ProductType,
|
||||
);
|
||||
const result = schedules.result.map((schedule: any) => {
|
||||
return {
|
||||
category:
|
||||
deviceDetails.productDevice.prodType == ProductType.CUR_2
|
||||
? schedule.category
|
||||
: schedule.category.replace('category_', ''),
|
||||
category: schedule.category.replace('category_', ''),
|
||||
enable: schedule.enable,
|
||||
function: {
|
||||
code: schedule.functions[0].code,
|
||||
@ -174,16 +159,6 @@ export class ScheduleService {
|
||||
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
|
||||
this.ensureProductTypeSupportedForSchedule(
|
||||
deviceDetails.productDevice.prodType as ProductType,
|
||||
@ -192,7 +167,6 @@ export class ScheduleService {
|
||||
await this.updateScheduleDeviceInTuya(
|
||||
deviceDetails.deviceTuyaUuid,
|
||||
updateScheduleDto,
|
||||
deviceDetails.productDevice.prodType as ProductType,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
@ -218,7 +192,6 @@ export class ScheduleService {
|
||||
private async addScheduleDeviceInTuya(
|
||||
deviceId: string,
|
||||
addScheduleDto: AddScheduleDto,
|
||||
deviceType: ProductType,
|
||||
): Promise<addScheduleDeviceInterface> {
|
||||
try {
|
||||
const convertedTime = convertTimestampToDubaiTime(addScheduleDto.time);
|
||||
@ -237,10 +210,7 @@ export class ScheduleService {
|
||||
...addScheduleDto.function,
|
||||
},
|
||||
],
|
||||
category:
|
||||
deviceType == ProductType.CUR_2
|
||||
? addScheduleDto.category
|
||||
: `category_${addScheduleDto.category}`,
|
||||
category: `category_${addScheduleDto.category}`,
|
||||
},
|
||||
});
|
||||
|
||||
@ -256,12 +226,9 @@ export class ScheduleService {
|
||||
private async getScheduleDeviceInTuya(
|
||||
deviceId: string,
|
||||
category: string,
|
||||
deviceType: ProductType,
|
||||
): Promise<getDeviceScheduleInterface> {
|
||||
try {
|
||||
const categoryToSent =
|
||||
deviceType == ProductType.CUR_2 ? category : `category_${category}`;
|
||||
const path = `/v2.0/cloud/timer/device/${deviceId}?category=${categoryToSent}`;
|
||||
const path = `/v2.0/cloud/timer/device/${deviceId}?category=category_${category}`;
|
||||
const response = await this.tuya.request({
|
||||
method: 'GET',
|
||||
path,
|
||||
@ -281,7 +248,6 @@ export class ScheduleService {
|
||||
private async updateScheduleDeviceInTuya(
|
||||
deviceId: string,
|
||||
updateScheduleDto: UpdateScheduleDto,
|
||||
deviceType: ProductType,
|
||||
): Promise<addScheduleDeviceInterface> {
|
||||
try {
|
||||
const convertedTime = convertTimestampToDubaiTime(updateScheduleDto.time);
|
||||
@ -302,10 +268,7 @@ export class ScheduleService {
|
||||
value: updateScheduleDto.function.value,
|
||||
},
|
||||
],
|
||||
category:
|
||||
deviceType == ProductType.CUR_2
|
||||
? updateScheduleDto.category
|
||||
: `category_${updateScheduleDto.category}`,
|
||||
category: `category_${updateScheduleDto.category}`,
|
||||
},
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user