mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-11 07:38:49 +00:00
Compare commits
1 Commits
main
...
feat/delet
Author | SHA1 | Date | |
---|---|---|---|
55593be79f |
17
.github/pull_request_template.md
vendored
17
.github/pull_request_template.md
vendored
@ -1,17 +0,0 @@
|
|||||||
<!--
|
|
||||||
Thanks for contributing!
|
|
||||||
|
|
||||||
Provide a description of your changes below and a general summary in the title.
|
|
||||||
-->
|
|
||||||
|
|
||||||
## Jira Ticket
|
|
||||||
|
|
||||||
[SP-0000](https://syncrow.atlassian.net/browse/SP-0000)
|
|
||||||
|
|
||||||
## Description
|
|
||||||
|
|
||||||
<!--- Describe your changes in detail -->
|
|
||||||
|
|
||||||
## How to Test
|
|
||||||
|
|
||||||
<!--- Describe the created APIs / Logic -->
|
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,7 +4,7 @@
|
|||||||
/build
|
/build
|
||||||
|
|
||||||
#github
|
#github
|
||||||
/.github/workflows
|
/.github
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
|
@ -15,7 +15,6 @@ export enum ProductType {
|
|||||||
WL = 'WL',
|
WL = 'WL',
|
||||||
GD = 'GD',
|
GD = 'GD',
|
||||||
CUR = 'CUR',
|
CUR = 'CUR',
|
||||||
CUR_2 = 'CUR_2',
|
|
||||||
PC = 'PC',
|
PC = 'PC',
|
||||||
FOUR_S = '4S',
|
FOUR_S = '4S',
|
||||||
SIX_S = '6S',
|
SIX_S = '6S',
|
||||||
|
@ -276,11 +276,9 @@ SELECT
|
|||||||
p.good_ch2o_percentage, p.moderate_ch2o_percentage, p.unhealthy_sensitive_ch2o_percentage, p.unhealthy_ch2o_percentage, p.very_unhealthy_ch2o_percentage, p.hazardous_ch2o_percentage,
|
p.good_ch2o_percentage, p.moderate_ch2o_percentage, p.unhealthy_sensitive_ch2o_percentage, p.unhealthy_ch2o_percentage, p.very_unhealthy_ch2o_percentage, p.hazardous_ch2o_percentage,
|
||||||
a.daily_avg_ch2o,a.daily_max_ch2o, a.daily_min_ch2o
|
a.daily_avg_ch2o,a.daily_max_ch2o, a.daily_min_ch2o
|
||||||
FROM daily_percentages p
|
FROM daily_percentages p
|
||||||
LEFT JOIN daily_averages a
|
LEFT JOIN daily_averages a
|
||||||
ON p.space_id = a.space_id AND p.event_date = a.event_date
|
ON p.space_id = a.space_id AND p.event_date = a.event_date
|
||||||
WHERE p.space_id = (SELECT space_id FROM params)
|
ORDER BY p.space_id, p.event_date)
|
||||||
AND p.event_date = (SELECT event_date FROM params)
|
|
||||||
ORDER BY p.space_id, p.event_date)
|
|
||||||
|
|
||||||
|
|
||||||
INSERT INTO public."space-daily-pollutant-stats" (
|
INSERT INTO public."space-daily-pollutant-stats" (
|
||||||
|
@ -111,7 +111,6 @@ 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) => {
|
||||||
@ -129,7 +128,7 @@ export class InviteUserService {
|
|||||||
await this.emailService.sendEmailWithInvitationTemplate(email, {
|
await this.emailService.sendEmailWithInvitationTemplate(email, {
|
||||||
name: firstName,
|
name: firstName,
|
||||||
invitationCode,
|
invitationCode,
|
||||||
role: invitedRoleType.replace(/_/g, ' '),
|
role: roleType,
|
||||||
spacesList: spaceNames,
|
spacesList: spaceNames,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { HttpException, HttpStatus, Injectable } from '@nestjs/common';
|
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
|
||||||
import { ConfigService } from '@nestjs/config';
|
|
||||||
import { TuyaContext } from '@tuya/tuya-connector-nodejs';
|
import { TuyaContext } from '@tuya/tuya-connector-nodejs';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
import {
|
import {
|
||||||
AddScheduleDto,
|
AddScheduleDto,
|
||||||
EnableScheduleDto,
|
EnableScheduleDto,
|
||||||
@ -11,14 +11,14 @@ import {
|
|||||||
getDeviceScheduleInterface,
|
getDeviceScheduleInterface,
|
||||||
} from '../interfaces/get.schedule.interface';
|
} from '../interfaces/get.schedule.interface';
|
||||||
|
|
||||||
import { ProductType } from '@app/common/constants/product-type.enum';
|
|
||||||
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||||
|
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||||
|
import { ProductType } from '@app/common/constants/product-type.enum';
|
||||||
import { convertTimestampToDubaiTime } from '@app/common/helper/convertTimestampToDubaiTime';
|
import { convertTimestampToDubaiTime } from '@app/common/helper/convertTimestampToDubaiTime';
|
||||||
import {
|
import {
|
||||||
getEnabledDays,
|
getEnabledDays,
|
||||||
getScheduleStatus,
|
getScheduleStatus,
|
||||||
} from '@app/common/helper/getScheduleStatus';
|
} from '@app/common/helper/getScheduleStatus';
|
||||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ScheduleService {
|
export class ScheduleService {
|
||||||
@ -57,8 +57,7 @@ export class ScheduleService {
|
|||||||
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.GD &&
|
deviceDetails.productDevice.prodType !== ProductType.GD
|
||||||
deviceDetails.productDevice.prodType !== ProductType.CUR_2
|
|
||||||
) {
|
) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
'This device is not supported for schedule',
|
'This device is not supported for schedule',
|
||||||
@ -116,8 +115,7 @@ export class ScheduleService {
|
|||||||
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.GD &&
|
deviceDetails.productDevice.prodType !== ProductType.GD
|
||||||
deviceDetails.productDevice.prodType !== ProductType.CUR_2
|
|
||||||
) {
|
) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
'This device is not supported for schedule',
|
'This device is not supported for schedule',
|
||||||
@ -162,16 +160,6 @@ 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,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Corrected condition for supported device types
|
// Corrected condition for supported device types
|
||||||
if (
|
if (
|
||||||
deviceDetails.productDevice.prodType !== ProductType.THREE_G &&
|
deviceDetails.productDevice.prodType !== ProductType.THREE_G &&
|
||||||
@ -181,8 +169,7 @@ export class ScheduleService {
|
|||||||
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.GD &&
|
deviceDetails.productDevice.prodType !== ProductType.GD
|
||||||
deviceDetails.productDevice.prodType !== ProductType.CUR_2
|
|
||||||
) {
|
) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
'This device is not supported for schedule',
|
'This device is not supported for schedule',
|
||||||
@ -192,7 +179,6 @@ 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(
|
||||||
@ -204,7 +190,6 @@ export class ScheduleService {
|
|||||||
async addScheduleDeviceInTuya(
|
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);
|
||||||
@ -224,10 +209,7 @@ export class ScheduleService {
|
|||||||
value: addScheduleDto.function.value,
|
value: addScheduleDto.function.value,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
category:
|
category: `category_${addScheduleDto.category}`,
|
||||||
deviceType == ProductType.CUR_2
|
|
||||||
? addScheduleDto.category
|
|
||||||
: `category_${addScheduleDto.category}`,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -255,8 +237,7 @@ export class ScheduleService {
|
|||||||
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.GD &&
|
deviceDetails.productDevice.prodType !== ProductType.GD
|
||||||
deviceDetails.productDevice.prodType !== ProductType.CUR_2
|
|
||||||
) {
|
) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
'This device is not supported for schedule',
|
'This device is not supported for schedule',
|
||||||
@ -266,14 +247,10 @@ 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:
|
category: schedule.category.replace('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,
|
||||||
@ -296,12 +273,9 @@ export class ScheduleService {
|
|||||||
async getScheduleDeviceInTuya(
|
async getScheduleDeviceInTuya(
|
||||||
deviceId: string,
|
deviceId: string,
|
||||||
category: string,
|
category: string,
|
||||||
deviceType: ProductType,
|
|
||||||
): Promise<getDeviceScheduleInterface> {
|
): Promise<getDeviceScheduleInterface> {
|
||||||
try {
|
try {
|
||||||
const categoryToSent =
|
const path = `/v2.0/cloud/timer/device/${deviceId}?category=category_${category}`;
|
||||||
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,
|
||||||
@ -340,16 +314,6 @@ 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
|
||||||
if (
|
if (
|
||||||
deviceDetails.productDevice.prodType !== ProductType.THREE_G &&
|
deviceDetails.productDevice.prodType !== ProductType.THREE_G &&
|
||||||
@ -359,8 +323,7 @@ export class ScheduleService {
|
|||||||
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
deviceDetails.productDevice.prodType !== ProductType.ONE_1TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
deviceDetails.productDevice.prodType !== ProductType.TWO_2TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
deviceDetails.productDevice.prodType !== ProductType.THREE_3TG &&
|
||||||
deviceDetails.productDevice.prodType !== ProductType.GD &&
|
deviceDetails.productDevice.prodType !== ProductType.GD
|
||||||
deviceDetails.productDevice.prodType !== ProductType.CUR_2
|
|
||||||
) {
|
) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
'This device is not supported for schedule',
|
'This device is not supported for schedule',
|
||||||
@ -370,7 +333,6 @@ 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(
|
||||||
@ -382,7 +344,6 @@ export class ScheduleService {
|
|||||||
async updateScheduleDeviceInTuya(
|
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);
|
||||||
@ -403,10 +364,7 @@ export class ScheduleService {
|
|||||||
value: updateScheduleDto.function.value,
|
value: updateScheduleDto.function.value,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
category:
|
category: `category_${updateScheduleDto.category}`,
|
||||||
deviceType == ProductType.CUR_2
|
|
||||||
? updateScheduleDto.category
|
|
||||||
: `category_${updateScheduleDto.category.replace('category_', '')}`,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user