mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 15:17:41 +00:00
Compare commits
53 Commits
refactor/a
...
d232c06ebe
Author | SHA1 | Date | |
---|---|---|---|
d232c06ebe | |||
5c916ed445 | |||
8f9b15f49f | |||
b9da00aaa6 | |||
5bf44a18e1 | |||
2b2772e4ca | |||
13c0f87fc6 | |||
c9d794d988 | |||
90ab291d83 | |||
5381a949bc | |||
6973e8b195 | |||
92d102d08f | |||
7dc28d0cb3 | |||
d9ad431a23 | |||
4bf43dab2b | |||
7520b8d9c7 | |||
72753b6dfb | |||
568eef8119 | |||
a40560a0b1 | |||
7d6f1bb944 | |||
434316fe51 | |||
287bb4c5e4 | |||
85602fa952 | |||
25a4d3e91b | |||
d3a560d18f | |||
ab99bb5afc | |||
67911d5ff1 | |||
13e3f3e213 | |||
327d678656 | |||
dd5447fc5f | |||
7df5b9ab08 | |||
06b4407b85 | |||
1d6f3b8e65 | |||
80659f7a48 | |||
4a5f2f3b9f | |||
a57f4e1c65 | |||
b2d52c7622 | |||
c9cbb2e085 | |||
8aa3de5fdc | |||
bc1ee9a53b | |||
19356c3833 | |||
8737ee992b | |||
e98a99be73 | |||
93efa15f3c | |||
c305e39ff2 | |||
61e4d220dc | |||
cd4bbe1788 | |||
d770a0c732 | |||
030e6ae902 | |||
9d8287b82b | |||
d741a6c1f3 | |||
6d55704dd4 | |||
d8ad9e55ea |
17
.github/pull_request_template.md
vendored
Normal file
17
.github/pull_request_template.md
vendored
Normal 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 -->
|
74
.github/workflows/main_syncrow(staging).yml
vendored
74
.github/workflows/main_syncrow(staging).yml
vendored
@ -1,4 +1,7 @@
|
|||||||
name: Backend deployment to Azure App Service
|
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
|
||||||
|
# More GitHub Actions for Azure: https://github.com/Azure/actions
|
||||||
|
|
||||||
|
name: Build and deploy container app to Azure Web App - syncrow(staging)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@ -6,50 +9,43 @@ on:
|
|||||||
- main
|
- main
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
|
|
||||||
env:
|
|
||||||
AZURE_WEB_APP_NAME: 'syncrow'
|
|
||||||
AZURE_WEB_APP_SLOT_NAME: 'staging'
|
|
||||||
ACR_REGISTRY: 'syncrow.azurecr.io'
|
|
||||||
IMAGE_NAME: 'backend'
|
|
||||||
IMAGE_TAG: 'latest'
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build_and_deploy:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: 'ubuntu-latest'
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v2
|
||||||
|
|
||||||
- name: Set up Node.js
|
- name: Set up Docker Buildx
|
||||||
uses: actions/setup-node@v3
|
uses: docker/setup-buildx-action@v2
|
||||||
|
|
||||||
|
- name: Log in to registry
|
||||||
|
uses: docker/login-action@v2
|
||||||
with:
|
with:
|
||||||
node-version: '20'
|
registry: https://syncrow.azurecr.io/
|
||||||
|
username: ${{ secrets.AzureAppService_ContainerUsername_47395803300340b49931ea82f6d80be3 }}
|
||||||
|
password: ${{ secrets.AzureAppService_ContainerPassword_e7b0ff54f54d44cba04a970a22384848 }}
|
||||||
|
|
||||||
- name: Install dependencies and build project
|
- name: Build and push container image to registry
|
||||||
run: |
|
uses: docker/build-push-action@v3
|
||||||
npm install
|
|
||||||
npm run build
|
|
||||||
|
|
||||||
- name: Log in to Azure
|
|
||||||
uses: azure/login@v1
|
|
||||||
with:
|
with:
|
||||||
creds: ${{ secrets.AZURE_CREDENTIALS }}
|
push: true
|
||||||
|
tags: syncrow.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_47395803300340b49931ea82f6d80be3 }}/syncrow/backend:${{ github.sha }}
|
||||||
|
file: ./Dockerfile
|
||||||
|
|
||||||
- name: Log in to Azure Container Registry
|
deploy:
|
||||||
run: az acr login --name ${{ env.ACR_REGISTRY }}
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
environment:
|
||||||
|
name: 'staging'
|
||||||
|
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
|
||||||
|
|
||||||
- name: List build output
|
steps:
|
||||||
run: ls -R dist/
|
- name: Deploy to Azure Web App
|
||||||
|
id: deploy-to-webapp
|
||||||
- name: Build and push Docker image
|
uses: azure/webapps-deploy@v2
|
||||||
run: |
|
with:
|
||||||
docker build . -t ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
|
app-name: 'syncrow'
|
||||||
docker push ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
|
slot-name: 'staging'
|
||||||
|
publish-profile: ${{ secrets.AzureAppService_PublishProfile_44f7766441ec4796b74789e9761ef589 }}
|
||||||
- name: Set Web App with Docker container
|
images: 'syncrow.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_47395803300340b49931ea82f6d80be3 }}/syncrow/backend:${{ github.sha }}'
|
||||||
run: |
|
|
||||||
az webapp config container set \
|
|
||||||
--name ${{ env.AZURE_WEB_APP_NAME }} \
|
|
||||||
--resource-group backend \
|
|
||||||
--docker-custom-image-name ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }} \
|
|
||||||
--docker-registry-server-url https://${{ env.ACR_REGISTRY }}
|
|
||||||
|
73
.github/workflows/main_syncrow(stg).yml
vendored
Normal file
73
.github/workflows/main_syncrow(stg).yml
vendored
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
|
||||||
|
# More GitHub Actions for Azure: https://github.com/Azure/actions
|
||||||
|
|
||||||
|
name: Build and deploy Node.js app to Azure Web App - syncrow
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
permissions:
|
||||||
|
contents: read #This is required for actions/checkout
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Set up Node.js version
|
||||||
|
uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: '20.x'
|
||||||
|
|
||||||
|
- name: npm install, build, and test
|
||||||
|
run: |
|
||||||
|
npm install
|
||||||
|
npm run build --if-present
|
||||||
|
npm run test --if-present
|
||||||
|
|
||||||
|
- name: Zip artifact for deployment
|
||||||
|
run: zip release.zip ./* -r
|
||||||
|
|
||||||
|
- name: Upload artifact for deployment job
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: node-app
|
||||||
|
path: release.zip
|
||||||
|
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: build
|
||||||
|
environment:
|
||||||
|
name: 'stg'
|
||||||
|
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
|
||||||
|
permissions:
|
||||||
|
id-token: write #This is required for requesting the JWT
|
||||||
|
contents: read #This is required for actions/checkout
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Download artifact from build job
|
||||||
|
uses: actions/download-artifact@v4
|
||||||
|
with:
|
||||||
|
name: node-app
|
||||||
|
|
||||||
|
- name: Unzip artifact for deployment
|
||||||
|
run: unzip release.zip
|
||||||
|
|
||||||
|
- name: Login to Azure
|
||||||
|
uses: azure/login@v2
|
||||||
|
with:
|
||||||
|
client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_515C8E782CFF431AB20448C85CA0FE58 }}
|
||||||
|
tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_2AEFE5534424490387C08FAE41573CC2 }}
|
||||||
|
subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_00623C33023749FEA5F6BC36884F9C8A }}
|
||||||
|
|
||||||
|
- name: 'Deploy to Azure Web App'
|
||||||
|
id: deploy-to-webapp
|
||||||
|
uses: azure/webapps-deploy@v3
|
||||||
|
with:
|
||||||
|
app-name: 'syncrow'
|
||||||
|
slot-name: 'stg'
|
||||||
|
package: .
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -4,7 +4,7 @@
|
|||||||
/build
|
/build
|
||||||
|
|
||||||
#github
|
#github
|
||||||
/.github
|
/.github/workflows
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
|
@ -397,6 +397,11 @@ export class ControllerRoute {
|
|||||||
public static readonly DELETE_USER_SUMMARY = 'Delete user by UUID';
|
public static readonly DELETE_USER_SUMMARY = 'Delete user by UUID';
|
||||||
public static readonly DELETE_USER_DESCRIPTION =
|
public static readonly DELETE_USER_DESCRIPTION =
|
||||||
'This endpoint deletes a user identified by their UUID. Accessible only by users with the Super Admin role.';
|
'This endpoint deletes a user identified by their UUID. Accessible only by users with the Super Admin role.';
|
||||||
|
|
||||||
|
public static readonly DELETE_USER_PROFILE_SUMMARY =
|
||||||
|
'Delete user profile by UUID';
|
||||||
|
public static readonly DELETE_USER_PROFILE_DESCRIPTION =
|
||||||
|
'This endpoint deletes a user profile identified by their UUID. Accessible only by users with the Super Admin role.';
|
||||||
public static readonly UPDATE_USER_WEB_AGREEMENT_SUMMARY =
|
public static readonly UPDATE_USER_WEB_AGREEMENT_SUMMARY =
|
||||||
'Update user web agreement by user UUID';
|
'Update user web agreement by user UUID';
|
||||||
public static readonly UPDATE_USER_WEB_AGREEMENT_DESCRIPTION =
|
public static readonly UPDATE_USER_WEB_AGREEMENT_DESCRIPTION =
|
||||||
@ -501,7 +506,6 @@ export class ControllerRoute {
|
|||||||
};
|
};
|
||||||
static PowerClamp = class {
|
static PowerClamp = class {
|
||||||
public static readonly ROUTE = 'power-clamp';
|
public static readonly ROUTE = 'power-clamp';
|
||||||
|
|
||||||
static ACTIONS = class {
|
static ACTIONS = class {
|
||||||
public static readonly GET_ENERGY_SUMMARY =
|
public static readonly GET_ENERGY_SUMMARY =
|
||||||
'Get power clamp historical data';
|
'Get power clamp historical data';
|
||||||
|
@ -15,6 +15,7 @@ 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',
|
||||||
|
@ -13,6 +13,7 @@ class StatusDto {
|
|||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
value: any;
|
value: any;
|
||||||
|
t?: string | number | Date;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AddDeviceStatusDto {
|
export class AddDeviceStatusDto {
|
||||||
|
@ -28,6 +28,8 @@ import { AqiDataService } from '@app/common/helper/services/aqi.data.service';
|
|||||||
export class DeviceStatusFirebaseService {
|
export class DeviceStatusFirebaseService {
|
||||||
private tuya: TuyaContext;
|
private tuya: TuyaContext;
|
||||||
private firebaseDb: Database;
|
private firebaseDb: Database;
|
||||||
|
private readonly isDevEnv: boolean;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
private readonly deviceRepository: DeviceRepository,
|
private readonly deviceRepository: DeviceRepository,
|
||||||
@ -47,6 +49,8 @@ export class DeviceStatusFirebaseService {
|
|||||||
|
|
||||||
// Initialize firebaseDb using firebaseDataBase function
|
// Initialize firebaseDb using firebaseDataBase function
|
||||||
this.firebaseDb = firebaseDataBase(this.configService);
|
this.firebaseDb = firebaseDataBase(this.configService);
|
||||||
|
this.isDevEnv =
|
||||||
|
this.configService.get<string>('NODE_ENV') === 'development';
|
||||||
}
|
}
|
||||||
async addDeviceStatusByDeviceUuid(
|
async addDeviceStatusByDeviceUuid(
|
||||||
deviceTuyaUuid: string,
|
deviceTuyaUuid: string,
|
||||||
@ -61,7 +65,7 @@ export class DeviceStatusFirebaseService {
|
|||||||
const deviceStatusSaved = await this.createDeviceStatusFirebase({
|
const deviceStatusSaved = await this.createDeviceStatusFirebase({
|
||||||
deviceUuid: device.uuid,
|
deviceUuid: device.uuid,
|
||||||
deviceTuyaUuid: deviceTuyaUuid,
|
deviceTuyaUuid: deviceTuyaUuid,
|
||||||
status: deviceStatus.status,
|
status: deviceStatus?.status,
|
||||||
productUuid: deviceStatus.productUuid,
|
productUuid: deviceStatus.productUuid,
|
||||||
productType: deviceStatus.productType,
|
productType: deviceStatus.productType,
|
||||||
});
|
});
|
||||||
@ -122,7 +126,7 @@ export class DeviceStatusFirebaseService {
|
|||||||
return {
|
return {
|
||||||
productUuid: deviceDetails.productDevice.uuid,
|
productUuid: deviceDetails.productDevice.uuid,
|
||||||
productType: deviceDetails.productDevice.prodType,
|
productType: deviceDetails.productDevice.prodType,
|
||||||
status: deviceStatus.result[0].status,
|
status: deviceStatus.result[0]?.status,
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw new HttpException(
|
throw new HttpException(
|
||||||
@ -187,18 +191,18 @@ export class DeviceStatusFirebaseService {
|
|||||||
if (!existingData.productType) {
|
if (!existingData.productType) {
|
||||||
existingData.productType = addDeviceStatusDto.productType;
|
existingData.productType = addDeviceStatusDto.productType;
|
||||||
}
|
}
|
||||||
if (!existingData.status) {
|
if (!existingData?.status) {
|
||||||
existingData.status = [];
|
existingData.status = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a map to track existing status codes
|
// Create a map to track existing status codes
|
||||||
const statusMap = new Map(
|
const statusMap = new Map(
|
||||||
existingData.status.map((item) => [item.code, item.value]),
|
existingData?.status.map((item) => [item.code, item.value]),
|
||||||
);
|
);
|
||||||
|
|
||||||
// Update or add status codes
|
// Update or add status codes
|
||||||
|
|
||||||
for (const statusItem of addDeviceStatusDto.status) {
|
for (const statusItem of addDeviceStatusDto?.status) {
|
||||||
statusMap.set(statusItem.code, statusItem.value);
|
statusMap.set(statusItem.code, statusItem.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -211,64 +215,126 @@ export class DeviceStatusFirebaseService {
|
|||||||
return existingData;
|
return existingData;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Save logs to your repository
|
if (this.isDevEnv) {
|
||||||
const newLogs = addDeviceStatusDto.log.properties.map((property) => {
|
// Save logs to your repository
|
||||||
return this.deviceStatusLogRepository.create({
|
const newLogs = addDeviceStatusDto.log.properties.map((property) => {
|
||||||
deviceId: addDeviceStatusDto.deviceUuid,
|
return this.deviceStatusLogRepository.create({
|
||||||
deviceTuyaId: addDeviceStatusDto.deviceTuyaUuid,
|
deviceId: addDeviceStatusDto.deviceUuid,
|
||||||
productId: addDeviceStatusDto.log.productId,
|
deviceTuyaId: addDeviceStatusDto.deviceTuyaUuid,
|
||||||
log: addDeviceStatusDto.log,
|
productId: addDeviceStatusDto.log.productId,
|
||||||
code: property.code,
|
log: addDeviceStatusDto.log,
|
||||||
value: property.value,
|
code: property.code,
|
||||||
eventId: addDeviceStatusDto.log.dataId,
|
value: property.value,
|
||||||
eventTime: new Date(property.time).toISOString(),
|
eventId: addDeviceStatusDto.log.dataId,
|
||||||
|
eventTime: new Date(property.time).toISOString(),
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
await this.deviceStatusLogRepository.save(newLogs);
|
||||||
await this.deviceStatusLogRepository.save(newLogs);
|
|
||||||
|
|
||||||
if (addDeviceStatusDto.productType === ProductType.PC) {
|
if (addDeviceStatusDto.productType === ProductType.PC) {
|
||||||
const energyCodes = new Set([
|
const energyCodes = new Set([
|
||||||
PowerClampEnergyEnum.ENERGY_CONSUMED,
|
PowerClampEnergyEnum.ENERGY_CONSUMED,
|
||||||
PowerClampEnergyEnum.ENERGY_CONSUMED_A,
|
PowerClampEnergyEnum.ENERGY_CONSUMED_A,
|
||||||
PowerClampEnergyEnum.ENERGY_CONSUMED_B,
|
PowerClampEnergyEnum.ENERGY_CONSUMED_B,
|
||||||
PowerClampEnergyEnum.ENERGY_CONSUMED_C,
|
PowerClampEnergyEnum.ENERGY_CONSUMED_C,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const energyStatus = addDeviceStatusDto?.log?.properties?.find((status) =>
|
const energyStatus = addDeviceStatusDto?.log?.properties?.find(
|
||||||
energyCodes.has(status.code),
|
(status) => energyCodes.has(status.code),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (energyStatus) {
|
if (energyStatus) {
|
||||||
await this.powerClampService.updateEnergyConsumedHistoricalData(
|
await this.powerClampService.updateEnergyConsumedHistoricalData(
|
||||||
|
addDeviceStatusDto.deviceUuid,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
addDeviceStatusDto.productType === ProductType.CPS ||
|
||||||
|
addDeviceStatusDto.productType === ProductType.WPS
|
||||||
|
) {
|
||||||
|
const occupancyCodes = new Set([PresenceSensorEnum.PRESENCE_STATE]);
|
||||||
|
|
||||||
|
const occupancyStatus = addDeviceStatusDto?.log?.properties?.find(
|
||||||
|
(status) => occupancyCodes.has(status.code),
|
||||||
|
);
|
||||||
|
|
||||||
|
if (occupancyStatus) {
|
||||||
|
await this.occupancyService.updateOccupancySensorHistoricalData(
|
||||||
|
addDeviceStatusDto.deviceUuid,
|
||||||
|
);
|
||||||
|
await this.occupancyService.updateOccupancySensorHistoricalDurationData(
|
||||||
|
addDeviceStatusDto.deviceUuid,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (addDeviceStatusDto.productType === ProductType.AQI) {
|
||||||
|
await this.aqiDataService.updateAQISensorHistoricalData(
|
||||||
addDeviceStatusDto.deviceUuid,
|
addDeviceStatusDto.deviceUuid,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
|
// Save logs to your repository
|
||||||
|
const newLogs = addDeviceStatusDto?.status.map((property) => {
|
||||||
|
return this.deviceStatusLogRepository.create({
|
||||||
|
deviceId: addDeviceStatusDto.deviceUuid,
|
||||||
|
deviceTuyaId: addDeviceStatusDto.deviceTuyaUuid,
|
||||||
|
productId: addDeviceStatusDto.log.productKey,
|
||||||
|
log: addDeviceStatusDto.log,
|
||||||
|
code: property.code,
|
||||||
|
value: property.value,
|
||||||
|
eventId: addDeviceStatusDto.log.dataId,
|
||||||
|
eventTime: new Date(property.t).toISOString(),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
await this.deviceStatusLogRepository.save(newLogs);
|
||||||
|
|
||||||
if (
|
if (addDeviceStatusDto.productType === ProductType.PC) {
|
||||||
addDeviceStatusDto.productType === ProductType.CPS ||
|
const energyCodes = new Set([
|
||||||
addDeviceStatusDto.productType === ProductType.WPS
|
PowerClampEnergyEnum.ENERGY_CONSUMED,
|
||||||
) {
|
PowerClampEnergyEnum.ENERGY_CONSUMED_A,
|
||||||
const occupancyCodes = new Set([PresenceSensorEnum.PRESENCE_STATE]);
|
PowerClampEnergyEnum.ENERGY_CONSUMED_B,
|
||||||
|
PowerClampEnergyEnum.ENERGY_CONSUMED_C,
|
||||||
|
]);
|
||||||
|
|
||||||
const occupancyStatus = addDeviceStatusDto?.log?.properties?.find(
|
const energyStatus = addDeviceStatusDto?.status?.find((status) => {
|
||||||
(status) => occupancyCodes.has(status.code),
|
return energyCodes.has(status.code as PowerClampEnergyEnum);
|
||||||
);
|
});
|
||||||
|
|
||||||
if (occupancyStatus) {
|
if (energyStatus) {
|
||||||
await this.occupancyService.updateOccupancySensorHistoricalData(
|
await this.powerClampService.updateEnergyConsumedHistoricalData(
|
||||||
addDeviceStatusDto.deviceUuid,
|
addDeviceStatusDto.deviceUuid,
|
||||||
);
|
);
|
||||||
await this.occupancyService.updateOccupancySensorHistoricalDurationData(
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
addDeviceStatusDto.productType === ProductType.CPS ||
|
||||||
|
addDeviceStatusDto.productType === ProductType.WPS
|
||||||
|
) {
|
||||||
|
const occupancyCodes = new Set([PresenceSensorEnum.PRESENCE_STATE]);
|
||||||
|
|
||||||
|
const occupancyStatus = addDeviceStatusDto?.status?.find((status) => {
|
||||||
|
return occupancyCodes.has(status.code as PresenceSensorEnum);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (occupancyStatus) {
|
||||||
|
await this.occupancyService.updateOccupancySensorHistoricalData(
|
||||||
|
addDeviceStatusDto.deviceUuid,
|
||||||
|
);
|
||||||
|
await this.occupancyService.updateOccupancySensorHistoricalDurationData(
|
||||||
|
addDeviceStatusDto.deviceUuid,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (addDeviceStatusDto.productType === ProductType.AQI) {
|
||||||
|
await this.aqiDataService.updateAQISensorHistoricalData(
|
||||||
addDeviceStatusDto.deviceUuid,
|
addDeviceStatusDto.deviceUuid,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (addDeviceStatusDto.productType === ProductType.AQI) {
|
|
||||||
await this.aqiDataService.updateAQISensorHistoricalData(
|
|
||||||
addDeviceStatusDto.deviceUuid,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// Return the updated data
|
// Return the updated data
|
||||||
const snapshot: DataSnapshot = await get(dataRef);
|
const snapshot: DataSnapshot = await get(dataRef);
|
||||||
return snapshot.val();
|
return snapshot.val();
|
||||||
|
@ -1,43 +1,26 @@
|
|||||||
import { utilities as nestWinstonModuleUtilities } from 'nest-winston';
|
import { utilities as nestWinstonModuleUtilities } from 'nest-winston';
|
||||||
import * as winston from 'winston';
|
import * as winston from 'winston';
|
||||||
const environment = process.env.NODE_ENV || 'local';
|
|
||||||
|
|
||||||
export const winstonLoggerOptions: winston.LoggerOptions = {
|
export const winstonLoggerOptions: winston.LoggerOptions = {
|
||||||
level:
|
level:
|
||||||
environment === 'local'
|
process.env.AZURE_POSTGRESQL_DATABASE === 'development' ? 'debug' : 'error',
|
||||||
? 'debug'
|
|
||||||
: environment === 'development'
|
|
||||||
? 'warn'
|
|
||||||
: 'error',
|
|
||||||
transports: [
|
transports: [
|
||||||
new winston.transports.Console({
|
new winston.transports.Console({
|
||||||
level:
|
|
||||||
environment === 'local'
|
|
||||||
? 'debug'
|
|
||||||
: environment === 'development'
|
|
||||||
? 'warn'
|
|
||||||
: 'error',
|
|
||||||
format: winston.format.combine(
|
format: winston.format.combine(
|
||||||
winston.format.timestamp(),
|
winston.format.timestamp(),
|
||||||
nestWinstonModuleUtilities.format.nestLike('MyApp', {
|
nestWinstonModuleUtilities.format.nestLike('MyApp', {
|
||||||
prettyPrint: environment === 'local',
|
prettyPrint: true,
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
// Only create file logs if NOT local
|
new winston.transports.File({
|
||||||
...(environment !== 'local'
|
filename: 'logs/error.log',
|
||||||
? [
|
level: 'error',
|
||||||
new winston.transports.File({
|
format: winston.format.json(),
|
||||||
filename: 'logs/error.log',
|
}),
|
||||||
level: 'error',
|
new winston.transports.File({
|
||||||
format: winston.format.json(),
|
filename: 'logs/combined.log',
|
||||||
}),
|
format: winston.format.json(),
|
||||||
new winston.transports.File({
|
}),
|
||||||
filename: 'logs/combined.log',
|
|
||||||
level: 'info',
|
|
||||||
format: winston.format.json(),
|
|
||||||
}),
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@ -8,14 +8,14 @@ import {
|
|||||||
Unique,
|
Unique,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
|
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
|
||||||
import { RoleTypeEntity } from '../../role-type/entities';
|
|
||||||
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
|
||||||
import { UserEntity } from '../../user/entities';
|
|
||||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||||
import { InviteUserDto, InviteUserSpaceDto } from '../dtos';
|
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
||||||
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { ProjectEntity } from '../../project/entities';
|
import { ProjectEntity } from '../../project/entities';
|
||||||
|
import { RoleTypeEntity } from '../../role-type/entities';
|
||||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||||
|
import { UserEntity } from '../../user/entities';
|
||||||
|
import { InviteUserDto, InviteUserSpaceDto } from '../dtos';
|
||||||
|
|
||||||
@Entity({ name: 'invite-user' })
|
@Entity({ name: 'invite-user' })
|
||||||
@Unique(['email', 'project'])
|
@Unique(['email', 'project'])
|
||||||
@ -82,7 +82,10 @@ export class InviteUserEntity extends AbstractEntity<InviteUserDto> {
|
|||||||
onDelete: 'CASCADE',
|
onDelete: 'CASCADE',
|
||||||
})
|
})
|
||||||
public roleType: RoleTypeEntity;
|
public roleType: RoleTypeEntity;
|
||||||
@OneToOne(() => UserEntity, (user) => user.inviteUser, { nullable: true })
|
@OneToOne(() => UserEntity, (user) => user.inviteUser, {
|
||||||
|
nullable: true,
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
})
|
||||||
@JoinColumn({ name: 'user_uuid' })
|
@JoinColumn({ name: 'user_uuid' })
|
||||||
user: UserEntity;
|
user: UserEntity;
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
@ -112,7 +115,9 @@ export class InviteUserSpaceEntity extends AbstractEntity<InviteUserSpaceDto> {
|
|||||||
})
|
})
|
||||||
public uuid: string;
|
public uuid: string;
|
||||||
|
|
||||||
@ManyToOne(() => InviteUserEntity, (inviteUser) => inviteUser.spaces)
|
@ManyToOne(() => InviteUserEntity, (inviteUser) => inviteUser.spaces, {
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
})
|
||||||
@JoinColumn({ name: 'invite_user_uuid' })
|
@JoinColumn({ name: 'invite_user_uuid' })
|
||||||
public inviteUser: InviteUserEntity;
|
public inviteUser: InviteUserEntity;
|
||||||
|
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
import {
|
import {
|
||||||
Column,
|
Column,
|
||||||
Entity,
|
Entity,
|
||||||
|
Index,
|
||||||
|
JoinColumn,
|
||||||
ManyToOne,
|
ManyToOne,
|
||||||
OneToMany,
|
OneToMany,
|
||||||
Unique,
|
Unique,
|
||||||
Index,
|
|
||||||
JoinColumn,
|
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { DeviceDto, DeviceUserPermissionDto } from '../dtos/device.dto';
|
|
||||||
import { ProductEntity } from '../../product/entities';
|
|
||||||
import { UserEntity } from '../../user/entities';
|
|
||||||
import { DeviceNotificationDto } from '../dtos';
|
|
||||||
import { PermissionTypeEntity } from '../../permission/entities';
|
import { PermissionTypeEntity } from '../../permission/entities';
|
||||||
|
import { PowerClampHourlyEntity } from '../../power-clamp/entities/power-clamp.entity';
|
||||||
|
import { PresenceSensorDailyDeviceEntity } from '../../presence-sensor/entities';
|
||||||
|
import { ProductEntity } from '../../product/entities';
|
||||||
import { SceneDeviceEntity } from '../../scene-device/entities';
|
import { SceneDeviceEntity } from '../../scene-device/entities';
|
||||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||||
import { SubspaceEntity } from '../../space/entities/subspace/subspace.entity';
|
import { SubspaceEntity } from '../../space/entities/subspace/subspace.entity';
|
||||||
import { NewTagEntity } from '../../tag';
|
import { NewTagEntity } from '../../tag';
|
||||||
import { PowerClampHourlyEntity } from '../../power-clamp/entities/power-clamp.entity';
|
import { UserEntity } from '../../user/entities';
|
||||||
import { PresenceSensorDailyDeviceEntity } from '../../presence-sensor/entities';
|
import { DeviceNotificationDto } from '../dtos';
|
||||||
|
import { DeviceDto, DeviceUserPermissionDto } from '../dtos/device.dto';
|
||||||
|
|
||||||
@Entity({ name: 'device' })
|
@Entity({ name: 'device' })
|
||||||
@Unique(['deviceTuyaUuid'])
|
@Unique(['deviceTuyaUuid'])
|
||||||
@ -111,6 +111,7 @@ export class DeviceNotificationEntity extends AbstractEntity<DeviceNotificationD
|
|||||||
|
|
||||||
@ManyToOne(() => UserEntity, (user) => user.userPermission, {
|
@ManyToOne(() => UserEntity, (user) => user.userPermission, {
|
||||||
nullable: false,
|
nullable: false,
|
||||||
|
onDelete: 'CASCADE',
|
||||||
})
|
})
|
||||||
user: UserEntity;
|
user: UserEntity;
|
||||||
|
|
||||||
@ -149,6 +150,7 @@ export class DeviceUserPermissionEntity extends AbstractEntity<DeviceUserPermiss
|
|||||||
|
|
||||||
@ManyToOne(() => UserEntity, (user) => user.userPermission, {
|
@ManyToOne(() => UserEntity, (user) => user.userPermission, {
|
||||||
nullable: false,
|
nullable: false,
|
||||||
|
onDelete: 'CASCADE',
|
||||||
})
|
})
|
||||||
user: UserEntity;
|
user: UserEntity;
|
||||||
constructor(partial: Partial<DeviceUserPermissionEntity>) {
|
constructor(partial: Partial<DeviceUserPermissionEntity>) {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { defaultProfilePicture } from '@app/common/constants/default.profile.picture';
|
||||||
import {
|
import {
|
||||||
Column,
|
Column,
|
||||||
DeleteDateColumn,
|
DeleteDateColumn,
|
||||||
@ -8,27 +9,26 @@ import {
|
|||||||
OneToOne,
|
OneToOne,
|
||||||
Unique,
|
Unique,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
|
import { OtpType } from '../../../../src/constants/otp-type.enum';
|
||||||
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
|
import { ClientEntity } from '../../client/entities';
|
||||||
|
import {
|
||||||
|
DeviceNotificationEntity,
|
||||||
|
DeviceUserPermissionEntity,
|
||||||
|
} from '../../device/entities';
|
||||||
|
import { InviteUserEntity } from '../../Invite-user/entities';
|
||||||
|
import { ProjectEntity } from '../../project/entities';
|
||||||
|
import { RegionEntity } from '../../region/entities';
|
||||||
|
import { RoleTypeEntity } from '../../role-type/entities';
|
||||||
|
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||||
|
import { TimeZoneEntity } from '../../timezone/entities';
|
||||||
|
import { VisitorPasswordEntity } from '../../visitor-password/entities';
|
||||||
import {
|
import {
|
||||||
UserDto,
|
UserDto,
|
||||||
UserNotificationDto,
|
UserNotificationDto,
|
||||||
UserOtpDto,
|
UserOtpDto,
|
||||||
UserSpaceDto,
|
UserSpaceDto,
|
||||||
} from '../dtos';
|
} from '../dtos';
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
|
||||||
import {
|
|
||||||
DeviceNotificationEntity,
|
|
||||||
DeviceUserPermissionEntity,
|
|
||||||
} from '../../device/entities';
|
|
||||||
import { defaultProfilePicture } from '@app/common/constants/default.profile.picture';
|
|
||||||
import { RegionEntity } from '../../region/entities';
|
|
||||||
import { TimeZoneEntity } from '../../timezone/entities';
|
|
||||||
import { OtpType } from '../../../../src/constants/otp-type.enum';
|
|
||||||
import { RoleTypeEntity } from '../../role-type/entities';
|
|
||||||
import { VisitorPasswordEntity } from '../../visitor-password/entities';
|
|
||||||
import { InviteUserEntity } from '../../Invite-user/entities';
|
|
||||||
import { ProjectEntity } from '../../project/entities';
|
|
||||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
|
||||||
import { ClientEntity } from '../../client/entities';
|
|
||||||
|
|
||||||
@Entity({ name: 'user' })
|
@Entity({ name: 'user' })
|
||||||
export class UserEntity extends AbstractEntity<UserDto> {
|
export class UserEntity extends AbstractEntity<UserDto> {
|
||||||
@ -94,7 +94,9 @@ export class UserEntity extends AbstractEntity<UserDto> {
|
|||||||
@Column({ type: 'timestamp', nullable: true })
|
@Column({ type: 'timestamp', nullable: true })
|
||||||
appAgreementAcceptedAt: Date;
|
appAgreementAcceptedAt: Date;
|
||||||
|
|
||||||
@OneToMany(() => UserSpaceEntity, (userSpace) => userSpace.user)
|
@OneToMany(() => UserSpaceEntity, (userSpace) => userSpace.user, {
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
})
|
||||||
userSpaces: UserSpaceEntity[];
|
userSpaces: UserSpaceEntity[];
|
||||||
|
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
@ -158,6 +160,7 @@ export class UserEntity extends AbstractEntity<UserDto> {
|
|||||||
export class UserNotificationEntity extends AbstractEntity<UserNotificationDto> {
|
export class UserNotificationEntity extends AbstractEntity<UserNotificationDto> {
|
||||||
@ManyToOne(() => UserEntity, (user) => user.roleType, {
|
@ManyToOne(() => UserEntity, (user) => user.roleType, {
|
||||||
nullable: false,
|
nullable: false,
|
||||||
|
onDelete: 'CASCADE',
|
||||||
})
|
})
|
||||||
user: UserEntity;
|
user: UserEntity;
|
||||||
@Column({
|
@Column({
|
||||||
@ -219,7 +222,10 @@ export class UserSpaceEntity extends AbstractEntity<UserSpaceDto> {
|
|||||||
})
|
})
|
||||||
public uuid: string;
|
public uuid: string;
|
||||||
|
|
||||||
@ManyToOne(() => UserEntity, (user) => user.userSpaces, { nullable: false })
|
@ManyToOne(() => UserEntity, (user) => user.userSpaces, {
|
||||||
|
nullable: false,
|
||||||
|
onDelete: 'CASCADE',
|
||||||
|
})
|
||||||
user: UserEntity;
|
user: UserEntity;
|
||||||
|
|
||||||
@ManyToOne(() => SpaceEntity, (space) => space.userSpaces, {
|
@ManyToOne(() => SpaceEntity, (space) => space.userSpaces, {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Column, Entity, ManyToOne, JoinColumn, Index } from 'typeorm';
|
import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
|
||||||
import { VisitorPasswordDto } from '../dtos';
|
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { UserEntity } from '../../user/entities/user.entity';
|
import { UserEntity } from '../../user/entities/user.entity';
|
||||||
|
import { VisitorPasswordDto } from '../dtos';
|
||||||
|
|
||||||
@Entity({ name: 'visitor-password' })
|
@Entity({ name: 'visitor-password' })
|
||||||
@Index('IDX_PASSWORD_TUYA_UUID', ['passwordTuyaUuid'])
|
@Index('IDX_PASSWORD_TUYA_UUID', ['passwordTuyaUuid'])
|
||||||
@ -14,6 +14,7 @@ export class VisitorPasswordEntity extends AbstractEntity<VisitorPasswordDto> {
|
|||||||
|
|
||||||
@ManyToOne(() => UserEntity, (user) => user.visitorPasswords, {
|
@ManyToOne(() => UserEntity, (user) => user.visitorPasswords, {
|
||||||
nullable: false,
|
nullable: false,
|
||||||
|
onDelete: 'CASCADE',
|
||||||
})
|
})
|
||||||
@JoinColumn({ name: 'authorizer_uuid' })
|
@JoinColumn({ name: 'authorizer_uuid' })
|
||||||
public user: UserEntity;
|
public user: UserEntity;
|
||||||
|
@ -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,
|
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
|
||||||
ORDER BY p.space_id, p.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" (
|
INSERT INTO public."space-daily-pollutant-stats" (
|
||||||
|
@ -87,5 +87,9 @@
|
|||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"tsconfig-paths": "^4.2.0",
|
"tsconfig-paths": "^4.2.0",
|
||||||
"typescript": "^5.1.3"
|
"typescript": "^5.1.3"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": "20.x",
|
||||||
|
"npm": "10.x"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,7 @@ export class CommunityService {
|
|||||||
.leftJoin('c.spaces', 's', 's.disabled = false')
|
.leftJoin('c.spaces', 's', 's.disabled = false')
|
||||||
.where('c.project = :projectUuid', { projectUuid })
|
.where('c.project = :projectUuid', { projectUuid })
|
||||||
.andWhere(`c.name != '${ORPHAN_COMMUNITY_NAME}-${project.name}'`)
|
.andWhere(`c.name != '${ORPHAN_COMMUNITY_NAME}-${project.name}'`)
|
||||||
|
.orderBy('c.createdAt', 'DESC')
|
||||||
.distinct(true);
|
.distinct(true);
|
||||||
if (pageable.search) {
|
if (pageable.search) {
|
||||||
qb.andWhere(
|
qb.andWhere(
|
||||||
|
@ -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,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,25 +1,24 @@
|
|||||||
|
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||||
|
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||||
|
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||||
|
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||||
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
|
import { Controller, Get, Param, Query, UseGuards } from '@nestjs/common';
|
||||||
import {
|
import {
|
||||||
ApiTags,
|
|
||||||
ApiBearerAuth,
|
ApiBearerAuth,
|
||||||
ApiOperation,
|
ApiOperation,
|
||||||
ApiParam,
|
ApiParam,
|
||||||
ApiQuery,
|
ApiQuery,
|
||||||
|
ApiTags,
|
||||||
} from '@nestjs/swagger';
|
} from '@nestjs/swagger';
|
||||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
|
||||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
|
||||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
|
||||||
import { PowerClampService } from '../services/power-clamp.service';
|
|
||||||
import {
|
import {
|
||||||
GetPowerClampBySpaceDto,
|
GetPowerClampBySpaceDto,
|
||||||
GetPowerClampDto,
|
GetPowerClampDto,
|
||||||
} from '../dto/get-power-clamp.dto';
|
} from '../dto/get-power-clamp.dto';
|
||||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
|
||||||
import {
|
import {
|
||||||
PowerClampParamsDto,
|
PowerClampParamsDto,
|
||||||
ResourceParamsDto,
|
ResourceParamsDto,
|
||||||
} from '../dto/power-clamp-params.dto';
|
} from '../dto/power-clamp-params.dto';
|
||||||
|
import { PowerClampService } from '../services/power-clamp.service';
|
||||||
@ApiTags('Power Clamp Module')
|
@ApiTags('Power Clamp Module')
|
||||||
@Controller({
|
@Controller({
|
||||||
version: EnableDisableStatusEnum.ENABLED,
|
version: EnableDisableStatusEnum.ENABLED,
|
||||||
@ -27,7 +26,6 @@ import {
|
|||||||
})
|
})
|
||||||
export class PowerClampController {
|
export class PowerClampController {
|
||||||
constructor(private readonly powerClampService: PowerClampService) {}
|
constructor(private readonly powerClampService: PowerClampService) {}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Get(':powerClampUuid/historical')
|
@Get(':powerClampUuid/historical')
|
||||||
|
@ -23,10 +23,10 @@ import { SpaceDeviceService } from 'src/space/services';
|
|||||||
import { SqlLoaderService } from '@app/common/helper/services/sql-loader.service';
|
import { SqlLoaderService } from '@app/common/helper/services/sql-loader.service';
|
||||||
import { DataSource } from 'typeorm';
|
import { DataSource } from 'typeorm';
|
||||||
import { SQL_PROCEDURES_PATH } from '@app/common/constants/sql-query-path';
|
import { SQL_PROCEDURES_PATH } from '@app/common/constants/sql-query-path';
|
||||||
import { filterByMonth, toMMYYYY } from '@app/common/helper/date-format';
|
|
||||||
import { ProductType } from '@app/common/constants/product-type.enum';
|
import { ProductType } from '@app/common/constants/product-type.enum';
|
||||||
import { CommunityService } from 'src/community/services';
|
import { CommunityService } from 'src/community/services';
|
||||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||||
|
import { filterByMonth, toMMYYYY } from '@app/common/helper/date-format';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PowerClampService {
|
export class PowerClampService {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { Injectable, HttpException, HttpStatus } from '@nestjs/common';
|
import { HttpException, HttpStatus, Injectable } 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 {
|
||||||
AddScheduleDto,
|
AddScheduleDto,
|
||||||
EnableScheduleDto,
|
EnableScheduleDto,
|
||||||
@ -11,14 +11,14 @@ import {
|
|||||||
getDeviceScheduleInterface,
|
getDeviceScheduleInterface,
|
||||||
} from '../interfaces/get.schedule.interface';
|
} from '../interfaces/get.schedule.interface';
|
||||||
|
|
||||||
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 { ProductType } from '@app/common/constants/product-type.enum';
|
||||||
|
import { convertKeysToCamelCase } from '@app/common/helper/camelCaseConverter';
|
||||||
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,7 +57,8 @@ 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',
|
||||||
@ -115,7 +116,8 @@ 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',
|
||||||
@ -160,6 +162,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,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 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 &&
|
||||||
@ -169,7 +181,8 @@ 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',
|
||||||
@ -179,6 +192,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(
|
||||||
@ -190,6 +204,7 @@ 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);
|
||||||
@ -209,7 +224,10 @@ export class ScheduleService {
|
|||||||
value: addScheduleDto.function.value,
|
value: addScheduleDto.function.value,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
category: `category_${addScheduleDto.category}`,
|
category:
|
||||||
|
deviceType == ProductType.CUR_2
|
||||||
|
? addScheduleDto.category
|
||||||
|
: `category_${addScheduleDto.category}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -237,7 +255,8 @@ 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',
|
||||||
@ -247,10 +266,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,
|
||||||
@ -273,9 +296,12 @@ export class ScheduleService {
|
|||||||
async getScheduleDeviceInTuya(
|
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,
|
||||||
@ -314,6 +340,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
|
||||||
if (
|
if (
|
||||||
deviceDetails.productDevice.prodType !== ProductType.THREE_G &&
|
deviceDetails.productDevice.prodType !== ProductType.THREE_G &&
|
||||||
@ -323,7 +359,8 @@ 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',
|
||||||
@ -333,6 +370,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(
|
||||||
@ -344,6 +382,7 @@ 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);
|
||||||
@ -364,7 +403,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.replace('category_', '')}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,3 +1,7 @@
|
|||||||
|
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||||
|
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||||
|
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||||
|
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||||
import {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
@ -7,10 +11,12 @@ import {
|
|||||||
Param,
|
Param,
|
||||||
Patch,
|
Patch,
|
||||||
Put,
|
Put,
|
||||||
|
Req,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { UserService } from '../services/user.service';
|
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
import { CheckProfilePictureGuard } from 'src/guards/profile.picture.guard';
|
||||||
|
import { SuperAdminRoleGuard } from 'src/guards/super.admin.role.guard';
|
||||||
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
|
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
|
||||||
import {
|
import {
|
||||||
UpdateNameDto,
|
UpdateNameDto,
|
||||||
@ -18,11 +24,7 @@ import {
|
|||||||
UpdateRegionDataDto,
|
UpdateRegionDataDto,
|
||||||
UpdateTimezoneDataDto,
|
UpdateTimezoneDataDto,
|
||||||
} from '../dtos';
|
} from '../dtos';
|
||||||
import { CheckProfilePictureGuard } from 'src/guards/profile.picture.guard';
|
import { UserService } from '../services/user.service';
|
||||||
import { SuperAdminRoleGuard } from 'src/guards/super.admin.role.guard';
|
|
||||||
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
|
||||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
|
||||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
|
||||||
|
|
||||||
@ApiTags('User Module')
|
@ApiTags('User Module')
|
||||||
@Controller({
|
@Controller({
|
||||||
@ -154,6 +156,32 @@ export class UserController {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@UseGuards(JwtAuthGuard)
|
||||||
|
@Delete('')
|
||||||
|
@ApiOperation({
|
||||||
|
summary: ControllerRoute.USER.ACTIONS.DELETE_USER_PROFILE_SUMMARY,
|
||||||
|
description: ControllerRoute.USER.ACTIONS.DELETE_USER_PROFILE_DESCRIPTION,
|
||||||
|
})
|
||||||
|
async deleteUserProfile(@Req() req: Request) {
|
||||||
|
const userUuid = req['user']?.userUuid;
|
||||||
|
const userRole = req['user']?.role;
|
||||||
|
if (!userUuid || (userRole && userRole == RoleType.SUPER_ADMIN)) {
|
||||||
|
throw {
|
||||||
|
statusCode: HttpStatus.UNAUTHORIZED,
|
||||||
|
message: 'Unauthorized',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
await this.userService.deleteUserProfile(userUuid);
|
||||||
|
return {
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
data: {
|
||||||
|
userId: userUuid,
|
||||||
|
},
|
||||||
|
message: 'User deleted successfully',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Patch('agreements/web/:userUuid')
|
@Patch('agreements/web/:userUuid')
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
import {
|
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||||
UpdateNameDto,
|
import { removeBase64Prefix } from '@app/common/helper/removeBase64Prefix';
|
||||||
UpdateProfilePictureDataDto,
|
import { RegionRepository } from '@app/common/modules/region/repositories';
|
||||||
UpdateRegionDataDto,
|
import { TimeZoneRepository } from '@app/common/modules/timezone/repositories';
|
||||||
UpdateTimezoneDataDto,
|
import { UserEntity } from '@app/common/modules/user/entities';
|
||||||
} from './../dtos/update.user.dto';
|
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
HttpException,
|
HttpException,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
Injectable,
|
Injectable,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
import {
|
||||||
import { RegionRepository } from '@app/common/modules/region/repositories';
|
UpdateNameDto,
|
||||||
import { TimeZoneRepository } from '@app/common/modules/timezone/repositories';
|
UpdateProfilePictureDataDto,
|
||||||
import { removeBase64Prefix } from '@app/common/helper/removeBase64Prefix';
|
UpdateRegionDataDto,
|
||||||
import { UserEntity } from '@app/common/modules/user/entities';
|
UpdateTimezoneDataDto,
|
||||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
} from './../dtos/update.user.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserService {
|
export class UserService {
|
||||||
@ -269,4 +269,12 @@ export class UserService {
|
|||||||
}
|
}
|
||||||
return await this.userRepository.update({ uuid }, { isActive: false });
|
return await this.userRepository.update({ uuid }, { isActive: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async deleteUserProfile(uuid: string) {
|
||||||
|
const user = await this.findOneById(uuid);
|
||||||
|
if (!user) {
|
||||||
|
throw new BadRequestException('User not found');
|
||||||
|
}
|
||||||
|
return this.userRepository.delete({ uuid });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user