Compare commits

...

8 Commits

Author SHA1 Message Date
d232c06ebe Merge pull request #449 from SyncrowIOT/fix-get-schedule-api
fix: adjust category handling for CUR_2 device type in schedule retrieval
2025-07-03 00:03:38 -06:00
5c916ed445 add pr template 2025-07-03 00:01:37 -06:00
8f9b15f49f fix: adjust category handling for CUR_2 device type in schedule retrieval 2025-06-30 07:12:43 -06:00
b9da00aaa6 Merge pull request #447 from SyncrowIOT/fix/integrate-cur2-with-schedule
add cur2 checks to schedule
2025-06-30 06:27:27 -06:00
5bf44a18e1 add cur2 checks to schedule 2025-06-30 14:09:32 +03:00
2b2772e4ca Merge pull request #445 from SyncrowIOT/fix-update-aqi-data-on-staging
fix: filter daily averages by space_id and event_date in update procedure
2025-06-30 04:11:03 -06:00
13c0f87fc6 fix: filter daily averages by space_id and event_date in update procedure 2025-06-30 04:09:40 -06:00
c9d794d988 fix: update role type formatting in user invitation email 2025-06-30 01:25:09 -06:00
5 changed files with 66 additions and 9 deletions

17
.github/pull_request_template.md vendored Normal file
View File

@ -0,0 +1,17 @@
<!--
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
View File

@ -4,7 +4,7 @@
/build
#github
/.github
/.github/workflows
# Logs
logs

View File

@ -276,9 +276,11 @@ 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,
a.daily_avg_ch2o,a.daily_max_ch2o, a.daily_min_ch2o
FROM daily_percentages p
LEFT JOIN daily_averages a
ON p.space_id = a.space_id AND p.event_date = a.event_date
ORDER BY p.space_id, p.event_date)
LEFT JOIN daily_averages a
ON p.space_id = a.space_id AND p.event_date = a.event_date
WHERE p.space_id = (SELECT space_id FROM params)
AND p.event_date = (SELECT event_date FROM params)
ORDER BY p.space_id, p.event_date)
INSERT INTO public."space-daily-pollutant-stats" (

View File

@ -111,6 +111,7 @@ 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) => {
@ -128,7 +129,7 @@ export class InviteUserService {
await this.emailService.sendEmailWithInvitationTemplate(email, {
name: firstName,
invitationCode,
role: roleType,
role: invitedRoleType.replace(/_/g, ' '),
spacesList: spaceNames,
});

View File

@ -162,6 +162,16 @@ 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,
);
}
// Corrected condition for supported device types
if (
deviceDetails.productDevice.prodType !== ProductType.THREE_G &&
@ -182,6 +192,7 @@ export class ScheduleService {
await this.addScheduleDeviceInTuya(
deviceDetails.deviceTuyaUuid,
addScheduleDto,
deviceDetails.productDevice.prodType as ProductType,
);
} catch (error) {
throw new HttpException(
@ -193,6 +204,7 @@ export class ScheduleService {
async addScheduleDeviceInTuya(
deviceId: string,
addScheduleDto: AddScheduleDto,
deviceType: ProductType,
): Promise<addScheduleDeviceInterface> {
try {
const convertedTime = convertTimestampToDubaiTime(addScheduleDto.time);
@ -212,7 +224,10 @@ export class ScheduleService {
value: addScheduleDto.function.value,
},
],
category: `category_${addScheduleDto.category}`,
category:
deviceType == ProductType.CUR_2
? addScheduleDto.category
: `category_${addScheduleDto.category}`,
},
});
@ -251,10 +266,14 @@ 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: schedule.category.replace('category_', ''),
category:
deviceDetails.productDevice.prodType == ProductType.CUR_2
? schedule.category
: schedule.category.replace('category_', ''),
enable: schedule.enable,
function: {
code: schedule.functions[0].code,
@ -277,9 +296,12 @@ export class ScheduleService {
async getScheduleDeviceInTuya(
deviceId: string,
category: string,
deviceType: ProductType,
): Promise<getDeviceScheduleInterface> {
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({
method: 'GET',
path,
@ -318,6 +340,16 @@ 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
if (
deviceDetails.productDevice.prodType !== ProductType.THREE_G &&
@ -338,6 +370,7 @@ export class ScheduleService {
await this.updateScheduleDeviceInTuya(
deviceDetails.deviceTuyaUuid,
updateScheduleDto,
deviceDetails.productDevice.prodType as ProductType,
);
} catch (error) {
throw new HttpException(
@ -349,6 +382,7 @@ export class ScheduleService {
async updateScheduleDeviceInTuya(
deviceId: string,
updateScheduleDto: UpdateScheduleDto,
deviceType: ProductType,
): Promise<addScheduleDeviceInterface> {
try {
const convertedTime = convertTimestampToDubaiTime(updateScheduleDto.time);
@ -369,7 +403,10 @@ export class ScheduleService {
value: updateScheduleDto.function.value,
},
],
category: `category_${updateScheduleDto.category}`,
category:
deviceType == ProductType.CUR_2
? updateScheduleDto.category
: `category_${updateScheduleDto.category.replace('category_', '')}`,
},
});