mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-11 07:38:49 +00:00
Compare commits
1 Commits
feat/imple
...
fix/add-de
Author | SHA1 | Date | |
---|---|---|---|
db8caf9c58 |
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 -->
|
|
82
.github/workflows/main_syncrow(staging).yml
vendored
82
.github/workflows/main_syncrow(staging).yml
vendored
@ -1,7 +1,4 @@
|
|||||||
# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
|
name: Backend deployment to Azure App Service
|
||||||
# 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:
|
||||||
@ -9,43 +6,50 @@ 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:
|
build_and_deploy:
|
||||||
runs-on: 'ubuntu-latest'
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v2
|
|
||||||
|
|
||||||
- name: Log in to registry
|
|
||||||
uses: docker/login-action@v2
|
|
||||||
with:
|
|
||||||
registry: https://syncrow.azurecr.io/
|
|
||||||
username: ${{ secrets.AzureAppService_ContainerUsername_47395803300340b49931ea82f6d80be3 }}
|
|
||||||
password: ${{ secrets.AzureAppService_ContainerPassword_e7b0ff54f54d44cba04a970a22384848 }}
|
|
||||||
|
|
||||||
- name: Build and push container image to registry
|
|
||||||
uses: docker/build-push-action@v3
|
|
||||||
with:
|
|
||||||
push: true
|
|
||||||
tags: syncrow.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_47395803300340b49931ea82f6d80be3 }}/syncrow/backend:${{ github.sha }}
|
|
||||||
file: ./Dockerfile
|
|
||||||
|
|
||||||
deploy:
|
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs: build
|
|
||||||
environment:
|
|
||||||
name: 'staging'
|
|
||||||
url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
|
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Deploy to Azure Web App
|
- uses: actions/checkout@v4
|
||||||
id: deploy-to-webapp
|
|
||||||
uses: azure/webapps-deploy@v2
|
- name: Set up Node.js
|
||||||
|
uses: actions/setup-node@v3
|
||||||
with:
|
with:
|
||||||
app-name: 'syncrow'
|
node-version: '20'
|
||||||
slot-name: 'staging'
|
|
||||||
publish-profile: ${{ secrets.AzureAppService_PublishProfile_44f7766441ec4796b74789e9761ef589 }}
|
- name: Install dependencies and build project
|
||||||
images: 'syncrow.azurecr.io/${{ secrets.AzureAppService_ContainerUsername_47395803300340b49931ea82f6d80be3 }}/syncrow/backend:${{ github.sha }}'
|
run: |
|
||||||
|
npm install
|
||||||
|
npm run build
|
||||||
|
|
||||||
|
- name: Log in to Azure
|
||||||
|
uses: azure/login@v1
|
||||||
|
with:
|
||||||
|
creds: ${{ secrets.AZURE_CREDENTIALS }}
|
||||||
|
|
||||||
|
- name: Log in to Azure Container Registry
|
||||||
|
run: az acr login --name ${{ env.ACR_REGISTRY }}
|
||||||
|
|
||||||
|
- name: List build output
|
||||||
|
run: ls -R dist/
|
||||||
|
|
||||||
|
- name: Build and push Docker image
|
||||||
|
run: |
|
||||||
|
docker build . -t ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
|
||||||
|
docker push ${{ env.ACR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG }}
|
||||||
|
|
||||||
|
- name: Set Web App with Docker container
|
||||||
|
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
73
.github/workflows/main_syncrow(stg).yml
vendored
@ -1,73 +0,0 @@
|
|||||||
# 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/workflows
|
/.github
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import { PlatformType } from '@app/common/constants/platform-type.enum';
|
import { PlatformType } from '@app/common/constants/platform-type.enum';
|
||||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||||
import { UserEntity } from '@app/common/modules/user/entities';
|
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
Injectable,
|
Injectable,
|
||||||
@ -33,7 +32,7 @@ export class AuthService {
|
|||||||
pass: string,
|
pass: string,
|
||||||
regionUuid?: string,
|
regionUuid?: string,
|
||||||
platform?: PlatformType,
|
platform?: PlatformType,
|
||||||
): Promise<Omit<UserEntity, 'password'>> {
|
): Promise<any> {
|
||||||
const user = await this.userRepository.findOne({
|
const user = await this.userRepository.findOne({
|
||||||
where: {
|
where: {
|
||||||
email,
|
email,
|
||||||
@ -71,9 +70,8 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
// const { password, ...result } = user;
|
const { password, ...result } = user;
|
||||||
delete user.password;
|
return result;
|
||||||
return user;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async createSession(data): Promise<UserSessionEntity> {
|
async createSession(data): Promise<UserSessionEntity> {
|
||||||
@ -116,7 +114,6 @@ export class AuthService {
|
|||||||
hasAcceptedWebAgreement: user.hasAcceptedWebAgreement,
|
hasAcceptedWebAgreement: user.hasAcceptedWebAgreement,
|
||||||
hasAcceptedAppAgreement: user.hasAcceptedAppAgreement,
|
hasAcceptedAppAgreement: user.hasAcceptedAppAgreement,
|
||||||
project: user?.project,
|
project: user?.project,
|
||||||
bookingPoints: user?.bookingPoints,
|
|
||||||
};
|
};
|
||||||
if (payload.googleCode) {
|
if (payload.googleCode) {
|
||||||
const profile = await this.getProfile(payload.googleCode);
|
const profile = await this.getProfile(payload.googleCode);
|
||||||
|
@ -69,47 +69,7 @@ export class ControllerRoute {
|
|||||||
'Retrieve the list of all regions registered in Syncrow.';
|
'Retrieve the list of all regions registered in Syncrow.';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
static BOOKABLE_SPACES = class {
|
|
||||||
public static readonly ROUTE = 'bookable-spaces';
|
|
||||||
static ACTIONS = class {
|
|
||||||
public static readonly ADD_BOOKABLE_SPACES_SUMMARY =
|
|
||||||
'Add new bookable spaces';
|
|
||||||
|
|
||||||
public static readonly ADD_BOOKABLE_SPACES_DESCRIPTION =
|
|
||||||
'This endpoint allows you to add new bookable spaces by providing the required details.';
|
|
||||||
|
|
||||||
public static readonly GET_ALL_BOOKABLE_SPACES_SUMMARY =
|
|
||||||
'Get all bookable spaces';
|
|
||||||
|
|
||||||
public static readonly GET_ALL_BOOKABLE_SPACES_DESCRIPTION =
|
|
||||||
'This endpoint retrieves all bookable spaces.';
|
|
||||||
|
|
||||||
public static readonly UPDATE_BOOKABLE_SPACES_SUMMARY =
|
|
||||||
'Update existing bookable spaces';
|
|
||||||
|
|
||||||
public static readonly UPDATE_BOOKABLE_SPACES_DESCRIPTION =
|
|
||||||
'This endpoint allows you to update existing bookable spaces by providing the required details.';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
static BOOKING = class {
|
|
||||||
public static readonly ROUTE = 'bookings';
|
|
||||||
static ACTIONS = class {
|
|
||||||
public static readonly ADD_BOOKING_SUMMARY = 'Add new booking';
|
|
||||||
|
|
||||||
public static readonly ADD_BOOKING_DESCRIPTION =
|
|
||||||
'This endpoint allows you to add new booking by providing the required details.';
|
|
||||||
|
|
||||||
public static readonly GET_ALL_BOOKINGS_SUMMARY = 'Get all bookings';
|
|
||||||
|
|
||||||
public static readonly GET_ALL_BOOKINGS_DESCRIPTION =
|
|
||||||
'This endpoint retrieves all bookings.';
|
|
||||||
|
|
||||||
public static readonly GET_MY_BOOKINGS_SUMMARY = 'Get my bookings';
|
|
||||||
|
|
||||||
public static readonly GET_MY_BOOKINGS_DESCRIPTION =
|
|
||||||
'This endpoint retrieves all bookings for the authenticated user.';
|
|
||||||
};
|
|
||||||
};
|
|
||||||
static COMMUNITY = class {
|
static COMMUNITY = class {
|
||||||
public static readonly ROUTE = '/projects/:projectUuid/communities';
|
public static readonly ROUTE = '/projects/:projectUuid/communities';
|
||||||
static ACTIONS = class {
|
static ACTIONS = class {
|
||||||
@ -239,11 +199,6 @@ export class ControllerRoute {
|
|||||||
public static readonly UPDATE_SPACE_DESCRIPTION =
|
public static readonly UPDATE_SPACE_DESCRIPTION =
|
||||||
'Updates a space by its UUID and community ID. You can update the name, parent space, and other properties. If a parent space is provided and not already a parent, its `isParent` flag will be set to true.';
|
'Updates a space by its UUID and community ID. You can update the name, parent space, and other properties. If a parent space is provided and not already a parent, its `isParent` flag will be set to true.';
|
||||||
|
|
||||||
public static readonly UPDATE_CHILDREN_SPACES_ORDER_OF_A_SPACE_SUMMARY =
|
|
||||||
'Update the order of child spaces under a specific parent space';
|
|
||||||
public static readonly UPDATE_CHILDREN_SPACES_ORDER_OF_A_SPACE_DESCRIPTION =
|
|
||||||
'Updates the order of child spaces under a specific parent space. You can provide a new order for the child spaces.';
|
|
||||||
|
|
||||||
public static readonly GET_HEIRARCHY_SUMMARY = 'Get space hierarchy';
|
public static readonly GET_HEIRARCHY_SUMMARY = 'Get space hierarchy';
|
||||||
public static readonly GET_HEIRARCHY_DESCRIPTION =
|
public static readonly GET_HEIRARCHY_DESCRIPTION =
|
||||||
'This endpoint retrieves the hierarchical structure of spaces under a given space ID. It returns all the child spaces nested within the specified space, organized by their parent-child relationships. ';
|
'This endpoint retrieves the hierarchical structure of spaces under a given space ID. It returns all the child spaces nested within the specified space, organized by their parent-child relationships. ';
|
||||||
@ -442,11 +397,6 @@ 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 =
|
||||||
@ -551,6 +501,7 @@ 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';
|
||||||
@ -677,11 +628,6 @@ export class ControllerRoute {
|
|||||||
'Delete scenes by device uuid and switch name';
|
'Delete scenes by device uuid and switch name';
|
||||||
public static readonly DELETE_SCENES_BY_SWITCH_NAME_DESCRIPTION =
|
public static readonly DELETE_SCENES_BY_SWITCH_NAME_DESCRIPTION =
|
||||||
'This endpoint deletes all scenes associated with a specific switch device.';
|
'This endpoint deletes all scenes associated with a specific switch device.';
|
||||||
|
|
||||||
public static readonly POPULATE_TUYA_CONST_UUID_SUMMARY =
|
|
||||||
'Populate Tuya const UUID';
|
|
||||||
public static readonly POPULATE_TUYA_CONST_UUID_DESCRIPTION =
|
|
||||||
'This endpoint populates the Tuya const UUID for all devices.';
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
static DEVICE_COMMISSION = class {
|
static DEVICE_COMMISSION = class {
|
||||||
|
@ -14,8 +14,6 @@ import { createLogger } from 'winston';
|
|||||||
import { winstonLoggerOptions } from '../logger/services/winston.logger';
|
import { winstonLoggerOptions } from '../logger/services/winston.logger';
|
||||||
import { AqiSpaceDailyPollutantStatsEntity } from '../modules/aqi/entities';
|
import { AqiSpaceDailyPollutantStatsEntity } from '../modules/aqi/entities';
|
||||||
import { AutomationEntity } from '../modules/automation/entities';
|
import { AutomationEntity } from '../modules/automation/entities';
|
||||||
import { BookableSpaceEntity } from '../modules/booking/entities/bookable-space.entity';
|
|
||||||
import { BookingEntity } from '../modules/booking/entities/booking.entity';
|
|
||||||
import { ClientEntity } from '../modules/client/entities';
|
import { ClientEntity } from '../modules/client/entities';
|
||||||
import { CommunityEntity } from '../modules/community/entities';
|
import { CommunityEntity } from '../modules/community/entities';
|
||||||
import { DeviceStatusLogEntity } from '../modules/device-status-log/entities';
|
import { DeviceStatusLogEntity } from '../modules/device-status-log/entities';
|
||||||
@ -119,8 +117,6 @@ import { VisitorPasswordEntity } from '../modules/visitor-password/entities';
|
|||||||
PresenceSensorDailySpaceEntity,
|
PresenceSensorDailySpaceEntity,
|
||||||
AqiSpaceDailyPollutantStatsEntity,
|
AqiSpaceDailyPollutantStatsEntity,
|
||||||
SpaceDailyOccupancyDurationEntity,
|
SpaceDailyOccupancyDurationEntity,
|
||||||
BookableSpaceEntity,
|
|
||||||
BookingEntity,
|
|
||||||
],
|
],
|
||||||
namingStrategy: new SnakeNamingStrategy(),
|
namingStrategy: new SnakeNamingStrategy(),
|
||||||
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
synchronize: Boolean(JSON.parse(configService.get('DB_SYNC'))),
|
||||||
|
@ -13,7 +13,6 @@ class StatusDto {
|
|||||||
|
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
value: any;
|
value: any;
|
||||||
t?: string | number | Date;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export class AddDeviceStatusDto {
|
export class AddDeviceStatusDto {
|
||||||
|
@ -22,8 +22,6 @@ import { DeviceStatusLogRepository } from '@app/common/modules/device-status-log
|
|||||||
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,
|
||||||
@ -40,8 +38,6 @@ 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,
|
||||||
@ -56,7 +52,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,
|
||||||
});
|
});
|
||||||
@ -195,7 +191,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(
|
||||||
@ -260,18 +256,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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
// Convert time string (HH:mm) to minutes
|
|
||||||
export function timeToMinutes(time: string): number {
|
|
||||||
const [hours, minutes] = time.split(':').map(Number);
|
|
||||||
return hours * 60 + minutes;
|
|
||||||
}
|
|
@ -49,12 +49,12 @@ export class TuyaService {
|
|||||||
path,
|
path,
|
||||||
});
|
});
|
||||||
|
|
||||||
// if (!response.success) {
|
if (!response.success) {
|
||||||
// throw new HttpException(
|
throw new HttpException(
|
||||||
// `Error fetching device details: ${response.msg}`,
|
`Error fetching device details: ${response.msg}`,
|
||||||
// HttpStatus.BAD_REQUEST,
|
HttpStatus.BAD_REQUEST,
|
||||||
// );
|
);
|
||||||
// }
|
}
|
||||||
|
|
||||||
return response.result;
|
return response.result;
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,43 @@
|
|||||||
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:
|
||||||
process.env.AZURE_POSTGRESQL_DATABASE === 'development' ? 'debug' : 'error',
|
environment === 'local'
|
||||||
|
? '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: true,
|
prettyPrint: environment === 'local',
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
}),
|
}),
|
||||||
new winston.transports.File({
|
// Only create file logs if NOT local
|
||||||
filename: 'logs/error.log',
|
...(environment !== 'local'
|
||||||
level: 'error',
|
? [
|
||||||
format: winston.format.json(),
|
new winston.transports.File({
|
||||||
}),
|
filename: 'logs/error.log',
|
||||||
new winston.transports.File({
|
level: 'error',
|
||||||
filename: 'logs/combined.log',
|
format: winston.format.json(),
|
||||||
format: winston.format.json(),
|
}),
|
||||||
}),
|
new winston.transports.File({
|
||||||
|
filename: 'logs/combined.log',
|
||||||
|
level: 'info',
|
||||||
|
format: winston.format.json(),
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
: []),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||||
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
||||||
import { IsEnum, IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
import { IsEnum, IsNotEmpty, IsString } from 'class-validator';
|
||||||
|
|
||||||
export class InviteUserDto {
|
export class InviteUserDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@ -12,12 +12,8 @@ export class InviteUserDto {
|
|||||||
public email: string;
|
public email: string;
|
||||||
|
|
||||||
@IsString()
|
@IsString()
|
||||||
@IsOptional()
|
@IsNotEmpty()
|
||||||
public jobTitle?: string;
|
public jobTitle: string;
|
||||||
|
|
||||||
@IsString()
|
|
||||||
@IsOptional()
|
|
||||||
public companyName?: string;
|
|
||||||
|
|
||||||
@IsEnum(UserStatusEnum)
|
@IsEnum(UserStatusEnum)
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
|
@ -8,14 +8,14 @@ import {
|
|||||||
Unique,
|
Unique,
|
||||||
} from 'typeorm';
|
} from 'typeorm';
|
||||||
|
|
||||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
|
||||||
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { ProjectEntity } from '../../project/entities';
|
|
||||||
import { RoleTypeEntity } from '../../role-type/entities';
|
import { RoleTypeEntity } from '../../role-type/entities';
|
||||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
||||||
import { UserEntity } from '../../user/entities';
|
import { UserEntity } from '../../user/entities';
|
||||||
|
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||||
import { InviteUserDto, InviteUserSpaceDto } from '../dtos';
|
import { InviteUserDto, InviteUserSpaceDto } from '../dtos';
|
||||||
|
import { ProjectEntity } from '../../project/entities';
|
||||||
|
import { SpaceEntity } from '../../space/entities/space.entity';
|
||||||
|
|
||||||
@Entity({ name: 'invite-user' })
|
@Entity({ name: 'invite-user' })
|
||||||
@Unique(['email', 'project'])
|
@Unique(['email', 'project'])
|
||||||
@ -37,11 +37,6 @@ export class InviteUserEntity extends AbstractEntity<InviteUserDto> {
|
|||||||
})
|
})
|
||||||
jobTitle: string;
|
jobTitle: string;
|
||||||
|
|
||||||
@Column({
|
|
||||||
nullable: true,
|
|
||||||
})
|
|
||||||
companyName: string;
|
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: false,
|
nullable: false,
|
||||||
enum: Object.values(UserStatusEnum),
|
enum: Object.values(UserStatusEnum),
|
||||||
@ -87,10 +82,7 @@ export class InviteUserEntity extends AbstractEntity<InviteUserDto> {
|
|||||||
onDelete: 'CASCADE',
|
onDelete: 'CASCADE',
|
||||||
})
|
})
|
||||||
public roleType: RoleTypeEntity;
|
public roleType: RoleTypeEntity;
|
||||||
@OneToOne(() => UserEntity, (user) => user.inviteUser, {
|
@OneToOne(() => UserEntity, (user) => user.inviteUser, { nullable: true })
|
||||||
nullable: true,
|
|
||||||
onDelete: 'CASCADE',
|
|
||||||
})
|
|
||||||
@JoinColumn({ name: 'user_uuid' })
|
@JoinColumn({ name: 'user_uuid' })
|
||||||
user: UserEntity;
|
user: UserEntity;
|
||||||
@OneToMany(
|
@OneToMany(
|
||||||
@ -120,9 +112,7 @@ 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,12 +0,0 @@
|
|||||||
import { Module } from '@nestjs/common';
|
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
|
||||||
import { BookableSpaceEntity } from './entities/bookable-space.entity';
|
|
||||||
import { BookingEntity } from './entities/booking.entity';
|
|
||||||
|
|
||||||
@Module({
|
|
||||||
providers: [],
|
|
||||||
exports: [],
|
|
||||||
controllers: [],
|
|
||||||
imports: [TypeOrmModule.forFeature([BookableSpaceEntity, BookingEntity])],
|
|
||||||
})
|
|
||||||
export class BookingRepositoryModule {}
|
|
@ -1,51 +0,0 @@
|
|||||||
import { DaysEnum } from '@app/common/constants/days.enum';
|
|
||||||
import {
|
|
||||||
Column,
|
|
||||||
CreateDateColumn,
|
|
||||||
Entity,
|
|
||||||
JoinColumn,
|
|
||||||
OneToOne,
|
|
||||||
UpdateDateColumn,
|
|
||||||
} from 'typeorm';
|
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
|
||||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
|
||||||
|
|
||||||
@Entity('bookable-space')
|
|
||||||
export class BookableSpaceEntity extends AbstractEntity {
|
|
||||||
@Column({
|
|
||||||
type: 'uuid',
|
|
||||||
default: () => 'gen_random_uuid()',
|
|
||||||
nullable: false,
|
|
||||||
})
|
|
||||||
public uuid: string;
|
|
||||||
|
|
||||||
@OneToOne(() => SpaceEntity, (space) => space.bookableConfig)
|
|
||||||
@JoinColumn({ name: 'space_uuid' })
|
|
||||||
space: SpaceEntity;
|
|
||||||
|
|
||||||
@Column({
|
|
||||||
type: 'enum',
|
|
||||||
enum: DaysEnum,
|
|
||||||
array: true,
|
|
||||||
nullable: false,
|
|
||||||
})
|
|
||||||
daysAvailable: DaysEnum[];
|
|
||||||
|
|
||||||
@Column({ type: 'time' })
|
|
||||||
startTime: string;
|
|
||||||
|
|
||||||
@Column({ type: 'time' })
|
|
||||||
endTime: string;
|
|
||||||
|
|
||||||
@Column({ type: Boolean, default: true })
|
|
||||||
active: boolean;
|
|
||||||
|
|
||||||
@Column({ type: 'int', default: null })
|
|
||||||
points?: number;
|
|
||||||
|
|
||||||
@CreateDateColumn()
|
|
||||||
createdAt: Date;
|
|
||||||
|
|
||||||
@UpdateDateColumn()
|
|
||||||
updatedAt: Date;
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
import {
|
|
||||||
Column,
|
|
||||||
CreateDateColumn,
|
|
||||||
Entity,
|
|
||||||
ManyToOne,
|
|
||||||
UpdateDateColumn,
|
|
||||||
} from 'typeorm';
|
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
|
||||||
import { SpaceEntity } from '../../space/entities/space.entity';
|
|
||||||
import { UserEntity } from '../../user/entities';
|
|
||||||
|
|
||||||
@Entity('booking')
|
|
||||||
export class BookingEntity extends AbstractEntity {
|
|
||||||
@Column({
|
|
||||||
type: 'uuid',
|
|
||||||
default: () => 'gen_random_uuid()',
|
|
||||||
nullable: false,
|
|
||||||
})
|
|
||||||
public uuid: string;
|
|
||||||
|
|
||||||
@ManyToOne(() => SpaceEntity, (space) => space.bookableConfig)
|
|
||||||
space: SpaceEntity;
|
|
||||||
|
|
||||||
@ManyToOne(() => UserEntity, (user) => user.bookings)
|
|
||||||
user: UserEntity;
|
|
||||||
|
|
||||||
@Column({ type: Date, nullable: false })
|
|
||||||
date: Date;
|
|
||||||
|
|
||||||
@Column({ type: 'time' })
|
|
||||||
startTime: string;
|
|
||||||
|
|
||||||
@Column({ type: 'time' })
|
|
||||||
endTime: string;
|
|
||||||
|
|
||||||
@Column({ type: 'int', default: null })
|
|
||||||
cost?: number;
|
|
||||||
|
|
||||||
@CreateDateColumn()
|
|
||||||
createdAt: Date;
|
|
||||||
|
|
||||||
@UpdateDateColumn()
|
|
||||||
updatedAt: Date;
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
import { DataSource, Repository } from 'typeorm';
|
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { BookableSpaceEntity } from '../entities/bookable-space.entity';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class BookableSpaceEntityRepository extends Repository<BookableSpaceEntity> {
|
|
||||||
constructor(private dataSource: DataSource) {
|
|
||||||
super(BookableSpaceEntity, dataSource.createEntityManager());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { DataSource, Repository } from 'typeorm';
|
|
||||||
import { BookingEntity } from '../entities/booking.entity';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class BookingEntityRepository extends Repository<BookingEntity> {
|
|
||||||
constructor(private dataSource: DataSource) {
|
|
||||||
super(BookingEntity, dataSource.createEntityManager());
|
|
||||||
}
|
|
||||||
}
|
|
@ -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 { PermissionTypeEntity } from '../../permission/entities';
|
import { DeviceDto, DeviceUserPermissionDto } from '../dtos/device.dto';
|
||||||
import { PowerClampHourlyEntity } from '../../power-clamp/entities/power-clamp.entity';
|
|
||||||
import { PresenceSensorDailyDeviceEntity } from '../../presence-sensor/entities';
|
|
||||||
import { ProductEntity } from '../../product/entities';
|
import { ProductEntity } from '../../product/entities';
|
||||||
|
import { UserEntity } from '../../user/entities';
|
||||||
|
import { DeviceNotificationDto } from '../dtos';
|
||||||
|
import { PermissionTypeEntity } from '../../permission/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 { UserEntity } from '../../user/entities';
|
import { PowerClampHourlyEntity } from '../../power-clamp/entities/power-clamp.entity';
|
||||||
import { DeviceNotificationDto } from '../dtos';
|
import { PresenceSensorDailyDeviceEntity } from '../../presence-sensor/entities';
|
||||||
import { DeviceDto, DeviceUserPermissionDto } from '../dtos/device.dto';
|
|
||||||
|
|
||||||
@Entity({ name: 'device' })
|
@Entity({ name: 'device' })
|
||||||
@Unique(['deviceTuyaUuid'])
|
@Unique(['deviceTuyaUuid'])
|
||||||
@ -28,11 +28,6 @@ export class DeviceEntity extends AbstractEntity<DeviceDto> {
|
|||||||
})
|
})
|
||||||
deviceTuyaUuid: string;
|
deviceTuyaUuid: string;
|
||||||
|
|
||||||
@Column({
|
|
||||||
nullable: true,
|
|
||||||
})
|
|
||||||
deviceTuyaConstUuid: string;
|
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
nullable: true,
|
nullable: true,
|
||||||
default: true,
|
default: true,
|
||||||
@ -116,7 +111,6 @@ 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;
|
||||||
|
|
||||||
@ -155,7 +149,6 @@ 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>) {
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
|
|
||||||
|
export class SpaceLinkEntity extends AbstractEntity {}
|
@ -1,14 +1,6 @@
|
|||||||
import {
|
import { Column, Entity, JoinColumn, ManyToOne, OneToMany } from 'typeorm';
|
||||||
Column,
|
|
||||||
Entity,
|
|
||||||
JoinColumn,
|
|
||||||
ManyToOne,
|
|
||||||
OneToMany,
|
|
||||||
OneToOne,
|
|
||||||
} from 'typeorm';
|
|
||||||
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
import { AbstractEntity } from '../../abstract/entities/abstract.entity';
|
||||||
import { AqiSpaceDailyPollutantStatsEntity } from '../../aqi/entities';
|
import { AqiSpaceDailyPollutantStatsEntity } from '../../aqi/entities';
|
||||||
import { BookableSpaceEntity } from '../../booking/entities/bookable-space.entity';
|
|
||||||
import { CommunityEntity } from '../../community/entities';
|
import { CommunityEntity } from '../../community/entities';
|
||||||
import { DeviceEntity } from '../../device/entities';
|
import { DeviceEntity } from '../../device/entities';
|
||||||
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
import { InviteUserSpaceEntity } from '../../Invite-user/entities';
|
||||||
@ -20,7 +12,6 @@ import { UserSpaceEntity } from '../../user/entities';
|
|||||||
import { SpaceDto } from '../dtos';
|
import { SpaceDto } from '../dtos';
|
||||||
import { SpaceProductAllocationEntity } from './space-product-allocation.entity';
|
import { SpaceProductAllocationEntity } from './space-product-allocation.entity';
|
||||||
import { SubspaceEntity } from './subspace/subspace.entity';
|
import { SubspaceEntity } from './subspace/subspace.entity';
|
||||||
import { BookingEntity } from '../../booking/entities/booking.entity';
|
|
||||||
|
|
||||||
@Entity({ name: 'space' })
|
@Entity({ name: 'space' })
|
||||||
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
||||||
@ -65,12 +56,6 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
|||||||
})
|
})
|
||||||
public disabled: boolean;
|
public disabled: boolean;
|
||||||
|
|
||||||
@Column({
|
|
||||||
nullable: true,
|
|
||||||
type: Number,
|
|
||||||
})
|
|
||||||
public order?: number;
|
|
||||||
|
|
||||||
@OneToMany(() => SubspaceEntity, (subspace) => subspace.space, {
|
@OneToMany(() => SubspaceEntity, (subspace) => subspace.space, {
|
||||||
nullable: true,
|
nullable: true,
|
||||||
})
|
})
|
||||||
@ -130,12 +115,6 @@ export class SpaceEntity extends AbstractEntity<SpaceDto> {
|
|||||||
)
|
)
|
||||||
occupancyDaily: SpaceDailyOccupancyDurationEntity[];
|
occupancyDaily: SpaceDailyOccupancyDurationEntity[];
|
||||||
|
|
||||||
@OneToOne(() => BookableSpaceEntity, (bookable) => bookable.space)
|
|
||||||
bookableConfig: BookableSpaceEntity;
|
|
||||||
|
|
||||||
@OneToMany(() => BookingEntity, (booking) => booking.space)
|
|
||||||
bookings: BookingEntity[];
|
|
||||||
|
|
||||||
constructor(partial: Partial<SpaceEntity>) {
|
constructor(partial: Partial<SpaceEntity>) {
|
||||||
super();
|
super();
|
||||||
Object.assign(this, partial);
|
Object.assign(this, partial);
|
||||||
|
@ -11,6 +11,9 @@ export class SpaceRepository extends Repository<SpaceEntity> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Injectable()
|
||||||
|
export class SpaceLinkRepository {}
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InviteSpaceRepository extends Repository<InviteSpaceEntity> {
|
export class InviteSpaceRepository extends Repository<InviteSpaceEntity> {
|
||||||
constructor(private dataSource: DataSource) {
|
constructor(private dataSource: DataSource) {
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { defaultProfilePicture } from '@app/common/constants/default.profile.picture';
|
|
||||||
import {
|
import {
|
||||||
Column,
|
Column,
|
||||||
DeleteDateColumn,
|
DeleteDateColumn,
|
||||||
@ -9,27 +8,27 @@ 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 { BookingEntity } from '../../booking/entities/booking.entity';
|
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> {
|
||||||
@ -83,12 +82,6 @@ export class UserEntity extends AbstractEntity<UserDto> {
|
|||||||
})
|
})
|
||||||
public isActive: boolean;
|
public isActive: boolean;
|
||||||
|
|
||||||
@Column({
|
|
||||||
nullable: true,
|
|
||||||
type: Number,
|
|
||||||
})
|
|
||||||
public bookingPoints?: number;
|
|
||||||
|
|
||||||
@Column({ default: false })
|
@Column({ default: false })
|
||||||
hasAcceptedWebAgreement: boolean;
|
hasAcceptedWebAgreement: boolean;
|
||||||
|
|
||||||
@ -101,9 +94,7 @@ 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(
|
||||||
@ -122,9 +113,6 @@ export class UserEntity extends AbstractEntity<UserDto> {
|
|||||||
)
|
)
|
||||||
deviceUserNotification: DeviceNotificationEntity[];
|
deviceUserNotification: DeviceNotificationEntity[];
|
||||||
|
|
||||||
@OneToMany(() => BookingEntity, (booking) => booking.user)
|
|
||||||
bookings: BookingEntity[];
|
|
||||||
|
|
||||||
@ManyToOne(() => RegionEntity, (region) => region.users, { nullable: true })
|
@ManyToOne(() => RegionEntity, (region) => region.users, { nullable: true })
|
||||||
region: RegionEntity;
|
region: RegionEntity;
|
||||||
@ManyToOne(() => TimeZoneEntity, (timezone) => timezone.users, {
|
@ManyToOne(() => TimeZoneEntity, (timezone) => timezone.users, {
|
||||||
@ -170,7 +158,6 @@ 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({
|
||||||
@ -232,10 +219,7 @@ export class UserSpaceEntity extends AbstractEntity<UserSpaceDto> {
|
|||||||
})
|
})
|
||||||
public uuid: string;
|
public uuid: string;
|
||||||
|
|
||||||
@ManyToOne(() => UserEntity, (user) => user.userSpaces, {
|
@ManyToOne(() => UserEntity, (user) => user.userSpaces, { nullable: false })
|
||||||
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, Index, JoinColumn, ManyToOne } from 'typeorm';
|
import { Column, Entity, ManyToOne, JoinColumn, Index } 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,7 +14,6 @@ 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;
|
||||||
|
3914
package-lock.json
generated
3914
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -56,7 +56,7 @@
|
|||||||
"onesignal-node": "^3.4.0",
|
"onesignal-node": "^3.4.0",
|
||||||
"passport-jwt": "^4.0.1",
|
"passport-jwt": "^4.0.1",
|
||||||
"pg": "^8.11.3",
|
"pg": "^8.11.3",
|
||||||
"reflect-metadata": "^0.2.2",
|
"reflect-metadata": "^0.2.0",
|
||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
"typeorm": "^0.3.20",
|
"typeorm": "^0.3.20",
|
||||||
"winston": "^3.17.0",
|
"winston": "^3.17.0",
|
||||||
@ -89,9 +89,5 @@
|
|||||||
"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"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,6 @@ import { OccupancyModule } from './occupancy/occupancy.module';
|
|||||||
import { WeatherModule } from './weather/weather.module';
|
import { WeatherModule } from './weather/weather.module';
|
||||||
import { ScheduleModule as NestScheduleModule } from '@nestjs/schedule';
|
import { ScheduleModule as NestScheduleModule } from '@nestjs/schedule';
|
||||||
import { SchedulerModule } from './scheduler/scheduler.module';
|
import { SchedulerModule } from './scheduler/scheduler.module';
|
||||||
import { BookingModule } from './booking';
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot({
|
ConfigModule.forRoot({
|
||||||
@ -99,7 +98,6 @@ import { BookingModule } from './booking';
|
|||||||
AqiModule,
|
AqiModule,
|
||||||
SchedulerModule,
|
SchedulerModule,
|
||||||
NestScheduleModule.forRoot(),
|
NestScheduleModule.forRoot(),
|
||||||
BookingModule,
|
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{
|
{
|
||||||
|
@ -1,25 +1,25 @@
|
|||||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
import { UserRepository } from '../../../libs/common/src/modules/user/repositories';
|
||||||
import { differenceInSeconds } from '@app/common/helper/differenceInSeconds';
|
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
ForbiddenException,
|
ForbiddenException,
|
||||||
Injectable,
|
Injectable,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ConfigService } from '@nestjs/config';
|
|
||||||
import * as argon2 from 'argon2';
|
|
||||||
import { RoleService } from 'src/role/services';
|
|
||||||
import { LessThan, MoreThan } from 'typeorm';
|
|
||||||
import { AuthService } from '../../../libs/common/src/auth/services/auth.service';
|
|
||||||
import { OtpType } from '../../../libs/common/src/constants/otp-type.enum';
|
|
||||||
import { HelperHashService } from '../../../libs/common/src/helper/services';
|
|
||||||
import { UserSessionRepository } from '../../../libs/common/src/modules/session/repositories/session.repository';
|
|
||||||
import { UserEntity } from '../../../libs/common/src/modules/user/entities/user.entity';
|
|
||||||
import { UserRepository } from '../../../libs/common/src/modules/user/repositories';
|
|
||||||
import { UserOtpRepository } from '../../../libs/common/src/modules/user/repositories/user.repository';
|
|
||||||
import { EmailService } from '../../../libs/common/src/util/email.service';
|
|
||||||
import { ForgetPasswordDto, UserOtpDto, VerifyOtpDto } from '../dtos';
|
|
||||||
import { UserSignUpDto } from '../dtos/user-auth.dto';
|
import { UserSignUpDto } from '../dtos/user-auth.dto';
|
||||||
|
import { HelperHashService } from '../../../libs/common/src/helper/services';
|
||||||
import { UserLoginDto } from '../dtos/user-login.dto';
|
import { UserLoginDto } from '../dtos/user-login.dto';
|
||||||
|
import { AuthService } from '../../../libs/common/src/auth/services/auth.service';
|
||||||
|
import { UserSessionRepository } from '../../../libs/common/src/modules/session/repositories/session.repository';
|
||||||
|
import { UserOtpRepository } from '../../../libs/common/src/modules/user/repositories/user.repository';
|
||||||
|
import { ForgetPasswordDto, UserOtpDto, VerifyOtpDto } from '../dtos';
|
||||||
|
import { EmailService } from '../../../libs/common/src/util/email.service';
|
||||||
|
import { OtpType } from '../../../libs/common/src/constants/otp-type.enum';
|
||||||
|
import { UserEntity } from '../../../libs/common/src/modules/user/entities/user.entity';
|
||||||
|
import * as argon2 from 'argon2';
|
||||||
|
import { differenceInSeconds } from '@app/common/helper/differenceInSeconds';
|
||||||
|
import { LessThan, MoreThan } from 'typeorm';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
import { RoleService } from 'src/role/services';
|
||||||
|
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserAuthService {
|
export class UserAuthService {
|
||||||
@ -108,7 +108,7 @@ export class UserAuthService {
|
|||||||
|
|
||||||
async userLogin(data: UserLoginDto) {
|
async userLogin(data: UserLoginDto) {
|
||||||
try {
|
try {
|
||||||
let user: Omit<UserEntity, 'password'>;
|
let user;
|
||||||
if (data.googleCode) {
|
if (data.googleCode) {
|
||||||
const googleUserData = await this.authService.login({
|
const googleUserData = await this.authService.login({
|
||||||
googleCode: data.googleCode,
|
googleCode: data.googleCode,
|
||||||
@ -145,7 +145,7 @@ export class UserAuthService {
|
|||||||
}
|
}
|
||||||
const session = await Promise.all([
|
const session = await Promise.all([
|
||||||
await this.sessionRepository.update(
|
await this.sessionRepository.update(
|
||||||
{ userId: user?.['id'] },
|
{ userId: user.id },
|
||||||
{
|
{
|
||||||
isLoggedOut: true,
|
isLoggedOut: true,
|
||||||
},
|
},
|
||||||
@ -166,7 +166,6 @@ export class UserAuthService {
|
|||||||
hasAcceptedAppAgreement: user.hasAcceptedAppAgreement,
|
hasAcceptedAppAgreement: user.hasAcceptedAppAgreement,
|
||||||
project: user.project,
|
project: user.project,
|
||||||
sessionId: session[1].uuid,
|
sessionId: session[1].uuid,
|
||||||
bookingPoints: user.bookingPoints,
|
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -348,7 +347,6 @@ export class UserAuthService {
|
|||||||
userId: user.uuid,
|
userId: user.uuid,
|
||||||
uuid: user.uuid,
|
uuid: user.uuid,
|
||||||
type,
|
type,
|
||||||
bookingPoints: user.bookingPoints,
|
|
||||||
sessionId,
|
sessionId,
|
||||||
});
|
});
|
||||||
await this.authService.updateRefreshToken(user.uuid, tokens.refreshToken);
|
await this.authService.updateRefreshToken(user.uuid, tokens.refreshToken);
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
import { BookingRepositoryModule } from '@app/common/modules/booking/booking.repository.module';
|
|
||||||
import { BookableSpaceEntityRepository } from '@app/common/modules/booking/repositories/bookable-space.repository';
|
|
||||||
import { BookingEntityRepository } from '@app/common/modules/booking/repositories/booking.repository';
|
|
||||||
import { SpaceRepository } from '@app/common/modules/space';
|
|
||||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
|
||||||
import { Global, Module } from '@nestjs/common';
|
|
||||||
import { BookableSpaceController } from './controllers/bookable-space.controller';
|
|
||||||
import { BookingController } from './controllers/booking.controller';
|
|
||||||
import { BookableSpaceService } from './services/bookable-space.service';
|
|
||||||
import { BookingService } from './services/booking.service';
|
|
||||||
|
|
||||||
@Global()
|
|
||||||
@Module({
|
|
||||||
imports: [BookingRepositoryModule],
|
|
||||||
controllers: [BookableSpaceController, BookingController],
|
|
||||||
providers: [
|
|
||||||
BookableSpaceService,
|
|
||||||
BookingService,
|
|
||||||
|
|
||||||
BookableSpaceEntityRepository,
|
|
||||||
BookingEntityRepository,
|
|
||||||
|
|
||||||
SpaceRepository,
|
|
||||||
UserRepository,
|
|
||||||
],
|
|
||||||
exports: [BookableSpaceService, BookingService],
|
|
||||||
})
|
|
||||||
export class BookingModule {}
|
|
@ -1,107 +0,0 @@
|
|||||||
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 {
|
|
||||||
Body,
|
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Param,
|
|
||||||
ParseUUIDPipe,
|
|
||||||
Post,
|
|
||||||
Put,
|
|
||||||
Query,
|
|
||||||
Req,
|
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
||||||
|
|
||||||
import { PageResponse } from '@app/common/dto/pagination.response.dto';
|
|
||||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
|
||||||
import { plainToInstance } from 'class-transformer';
|
|
||||||
import { BookableSpaceRequestDto } from '../dtos/bookable-space-request.dto';
|
|
||||||
import { BookableSpaceResponseDto } from '../dtos/bookable-space-response.dto';
|
|
||||||
import { CreateBookableSpaceDto } from '../dtos/create-bookable-space.dto';
|
|
||||||
import { UpdateBookableSpaceDto } from '../dtos/update-bookable-space.dto';
|
|
||||||
import { BookableSpaceService } from '../services/bookable-space.service';
|
|
||||||
|
|
||||||
@ApiTags('Booking Module')
|
|
||||||
@Controller({
|
|
||||||
version: EnableDisableStatusEnum.ENABLED,
|
|
||||||
path: ControllerRoute.BOOKABLE_SPACES.ROUTE,
|
|
||||||
})
|
|
||||||
export class BookableSpaceController {
|
|
||||||
constructor(private readonly bookableSpaceService: BookableSpaceService) {}
|
|
||||||
@ApiBearerAuth()
|
|
||||||
@UseGuards(JwtAuthGuard)
|
|
||||||
@Post()
|
|
||||||
@ApiOperation({
|
|
||||||
summary:
|
|
||||||
ControllerRoute.BOOKABLE_SPACES.ACTIONS.ADD_BOOKABLE_SPACES_SUMMARY,
|
|
||||||
description:
|
|
||||||
ControllerRoute.BOOKABLE_SPACES.ACTIONS.ADD_BOOKABLE_SPACES_DESCRIPTION,
|
|
||||||
})
|
|
||||||
async create(@Body() dto: CreateBookableSpaceDto): Promise<BaseResponseDto> {
|
|
||||||
const result = await this.bookableSpaceService.create(dto);
|
|
||||||
return new SuccessResponseDto({
|
|
||||||
data: result,
|
|
||||||
message: 'Successfully created bookable spaces',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiBearerAuth()
|
|
||||||
@UseGuards(JwtAuthGuard)
|
|
||||||
@Get()
|
|
||||||
@ApiOperation({
|
|
||||||
summary:
|
|
||||||
ControllerRoute.BOOKABLE_SPACES.ACTIONS.GET_ALL_BOOKABLE_SPACES_SUMMARY,
|
|
||||||
description:
|
|
||||||
ControllerRoute.BOOKABLE_SPACES.ACTIONS
|
|
||||||
.GET_ALL_BOOKABLE_SPACES_DESCRIPTION,
|
|
||||||
})
|
|
||||||
async findAll(
|
|
||||||
@Query() query: BookableSpaceRequestDto,
|
|
||||||
@Req() req: Request,
|
|
||||||
): Promise<PageResponse<BookableSpaceResponseDto>> {
|
|
||||||
const project = req['user']?.project?.uuid;
|
|
||||||
if (!project) {
|
|
||||||
throw new Error('Project UUID is required in the request');
|
|
||||||
}
|
|
||||||
const { data, pagination } = await this.bookableSpaceService.findAll(
|
|
||||||
query,
|
|
||||||
project,
|
|
||||||
);
|
|
||||||
return new PageResponse<BookableSpaceResponseDto>(
|
|
||||||
{
|
|
||||||
data: data.map((space) =>
|
|
||||||
plainToInstance(BookableSpaceResponseDto, space, {
|
|
||||||
excludeExtraneousValues: true,
|
|
||||||
}),
|
|
||||||
),
|
|
||||||
message: 'Successfully fetched all bookable spaces',
|
|
||||||
},
|
|
||||||
pagination,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiBearerAuth()
|
|
||||||
@UseGuards(JwtAuthGuard)
|
|
||||||
@Put(':spaceUuid')
|
|
||||||
@ApiOperation({
|
|
||||||
summary:
|
|
||||||
ControllerRoute.BOOKABLE_SPACES.ACTIONS.UPDATE_BOOKABLE_SPACES_SUMMARY,
|
|
||||||
description:
|
|
||||||
ControllerRoute.BOOKABLE_SPACES.ACTIONS
|
|
||||||
.UPDATE_BOOKABLE_SPACES_DESCRIPTION,
|
|
||||||
})
|
|
||||||
async update(
|
|
||||||
@Param('spaceUuid', ParseUUIDPipe) spaceUuid: string,
|
|
||||||
@Body() dto: UpdateBookableSpaceDto,
|
|
||||||
): Promise<BaseResponseDto> {
|
|
||||||
const result = await this.bookableSpaceService.update(spaceUuid, dto);
|
|
||||||
return new SuccessResponseDto({
|
|
||||||
data: result,
|
|
||||||
message: 'Successfully updated bookable spaces',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,107 +0,0 @@
|
|||||||
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 {
|
|
||||||
Body,
|
|
||||||
Controller,
|
|
||||||
Get,
|
|
||||||
Post,
|
|
||||||
Query,
|
|
||||||
Req,
|
|
||||||
UseGuards,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
||||||
|
|
||||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
|
||||||
import { plainToInstance } from 'class-transformer';
|
|
||||||
import { AdminRoleGuard } from 'src/guards/admin.role.guard';
|
|
||||||
import { BookingRequestDto } from '../dtos/booking-request.dto';
|
|
||||||
import { BookingResponseDto } from '../dtos/booking-response.dto';
|
|
||||||
import { CreateBookingDto } from '../dtos/create-booking.dto';
|
|
||||||
import { MyBookingRequestDto } from '../dtos/my-booking-request.dto';
|
|
||||||
import { BookingService } from '../services/booking.service';
|
|
||||||
|
|
||||||
@ApiTags('Booking Module')
|
|
||||||
@Controller({
|
|
||||||
version: EnableDisableStatusEnum.ENABLED,
|
|
||||||
path: ControllerRoute.BOOKING.ROUTE,
|
|
||||||
})
|
|
||||||
export class BookingController {
|
|
||||||
constructor(private readonly bookingService: BookingService) {}
|
|
||||||
|
|
||||||
@ApiBearerAuth()
|
|
||||||
@UseGuards(JwtAuthGuard)
|
|
||||||
@Post()
|
|
||||||
@ApiOperation({
|
|
||||||
summary: ControllerRoute.BOOKING.ACTIONS.ADD_BOOKING_SUMMARY,
|
|
||||||
description: ControllerRoute.BOOKING.ACTIONS.ADD_BOOKING_DESCRIPTION,
|
|
||||||
})
|
|
||||||
async create(
|
|
||||||
@Body() dto: CreateBookingDto,
|
|
||||||
@Req() req: Request,
|
|
||||||
): Promise<BaseResponseDto> {
|
|
||||||
const userUuid = req['user']?.uuid;
|
|
||||||
if (!userUuid) {
|
|
||||||
throw new Error('User UUID is required in the request');
|
|
||||||
}
|
|
||||||
const result = await this.bookingService.create(userUuid, dto);
|
|
||||||
return new SuccessResponseDto({
|
|
||||||
data: result,
|
|
||||||
message: 'Successfully created booking',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiBearerAuth()
|
|
||||||
@UseGuards(AdminRoleGuard)
|
|
||||||
@Get()
|
|
||||||
@ApiOperation({
|
|
||||||
summary: ControllerRoute.BOOKING.ACTIONS.GET_ALL_BOOKINGS_SUMMARY,
|
|
||||||
description: ControllerRoute.BOOKING.ACTIONS.GET_ALL_BOOKINGS_DESCRIPTION,
|
|
||||||
})
|
|
||||||
async findAll(
|
|
||||||
@Query() query: BookingRequestDto,
|
|
||||||
@Req() req: Request,
|
|
||||||
): Promise<BaseResponseDto> {
|
|
||||||
const project = req['user']?.project?.uuid;
|
|
||||||
if (!project) {
|
|
||||||
throw new Error('Project UUID is required in the request');
|
|
||||||
}
|
|
||||||
const result = await this.bookingService.findAll(query, project);
|
|
||||||
return new SuccessResponseDto({
|
|
||||||
data: plainToInstance(BookingResponseDto, result, {
|
|
||||||
excludeExtraneousValues: true,
|
|
||||||
}),
|
|
||||||
message: 'Successfully fetched all bookings',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiBearerAuth()
|
|
||||||
@UseGuards(JwtAuthGuard)
|
|
||||||
@Get('my-bookings')
|
|
||||||
@ApiOperation({
|
|
||||||
summary: ControllerRoute.BOOKING.ACTIONS.GET_MY_BOOKINGS_SUMMARY,
|
|
||||||
description: ControllerRoute.BOOKING.ACTIONS.GET_MY_BOOKINGS_DESCRIPTION,
|
|
||||||
})
|
|
||||||
async findMyBookings(
|
|
||||||
@Query() query: MyBookingRequestDto,
|
|
||||||
@Req() req: Request,
|
|
||||||
): Promise<BaseResponseDto> {
|
|
||||||
const userUuid = req['user']?.uuid;
|
|
||||||
const project = req['user']?.project?.uuid;
|
|
||||||
if (!project) {
|
|
||||||
throw new Error('Project UUID is required in the request');
|
|
||||||
}
|
|
||||||
const result = await this.bookingService.findMyBookings(
|
|
||||||
query,
|
|
||||||
userUuid,
|
|
||||||
project,
|
|
||||||
);
|
|
||||||
return new SuccessResponseDto({
|
|
||||||
data: plainToInstance(BookingResponseDto, result, {
|
|
||||||
excludeExtraneousValues: true,
|
|
||||||
}),
|
|
||||||
message: 'Successfully fetched all bookings',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,31 +0,0 @@
|
|||||||
import { BooleanValues } from '@app/common/constants/boolean-values.enum';
|
|
||||||
import { PaginationRequestWithSearchGetListDto } from '@app/common/dto/pagination-with-search.request.dto';
|
|
||||||
import { ApiProperty, OmitType } from '@nestjs/swagger';
|
|
||||||
import { Transform } from 'class-transformer';
|
|
||||||
import { IsBoolean, IsNotEmpty, IsOptional } from 'class-validator';
|
|
||||||
|
|
||||||
export class BookableSpaceRequestDto extends OmitType(
|
|
||||||
PaginationRequestWithSearchGetListDto,
|
|
||||||
['includeSpaces'],
|
|
||||||
) {
|
|
||||||
@ApiProperty({
|
|
||||||
type: Boolean,
|
|
||||||
required: false,
|
|
||||||
})
|
|
||||||
@IsBoolean()
|
|
||||||
@IsOptional()
|
|
||||||
@Transform(({ obj }) => {
|
|
||||||
return obj.active === BooleanValues.TRUE;
|
|
||||||
})
|
|
||||||
active?: boolean;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: Boolean,
|
|
||||||
})
|
|
||||||
@IsBoolean()
|
|
||||||
@IsNotEmpty()
|
|
||||||
@Transform(({ obj }) => {
|
|
||||||
return obj.configured === BooleanValues.TRUE;
|
|
||||||
})
|
|
||||||
configured: boolean;
|
|
||||||
}
|
|
@ -1,59 +0,0 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
|
||||||
import { Expose, Type } from 'class-transformer';
|
|
||||||
export class BookableSpaceConfigResponseDto {
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
uuid: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: [String],
|
|
||||||
})
|
|
||||||
@Expose()
|
|
||||||
daysAvailable: string[];
|
|
||||||
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
startTime: string;
|
|
||||||
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
endTime: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: Boolean,
|
|
||||||
})
|
|
||||||
@Expose()
|
|
||||||
active: boolean;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: Number,
|
|
||||||
nullable: true,
|
|
||||||
})
|
|
||||||
@Expose()
|
|
||||||
points?: number;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class BookableSpaceResponseDto {
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
uuid: string;
|
|
||||||
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
spaceUuid: string;
|
|
||||||
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
spaceName: string;
|
|
||||||
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
virtualLocation: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: BookableSpaceConfigResponseDto,
|
|
||||||
})
|
|
||||||
@Expose()
|
|
||||||
@Type(() => BookableSpaceConfigResponseDto)
|
|
||||||
bookableConfig: BookableSpaceConfigResponseDto;
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
|
||||||
import { IsNotEmpty, Matches } from 'class-validator';
|
|
||||||
|
|
||||||
export class BookingRequestDto {
|
|
||||||
@ApiProperty({
|
|
||||||
description: 'Month in MM/YYYY format',
|
|
||||||
example: '07/2025',
|
|
||||||
})
|
|
||||||
@IsNotEmpty()
|
|
||||||
@Matches(/^(0[1-9]|1[0-2])\/\d{4}$/, {
|
|
||||||
message: 'Date must be in MM/YYYY format',
|
|
||||||
})
|
|
||||||
month: string;
|
|
||||||
}
|
|
@ -1,90 +0,0 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
|
||||||
import { Expose, Transform, Type } from 'class-transformer';
|
|
||||||
|
|
||||||
export class BookingUserResponseDto {
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
uuid: string;
|
|
||||||
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
firstName: string;
|
|
||||||
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
lastName: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: String,
|
|
||||||
nullable: true,
|
|
||||||
})
|
|
||||||
@Expose()
|
|
||||||
email: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: String,
|
|
||||||
nullable: true,
|
|
||||||
})
|
|
||||||
@Expose()
|
|
||||||
@Transform(({ obj }) => {
|
|
||||||
return {
|
|
||||||
companyName: obj.inviteUser?.companyName || null,
|
|
||||||
};
|
|
||||||
})
|
|
||||||
@ApiProperty({
|
|
||||||
type: String,
|
|
||||||
nullable: true,
|
|
||||||
})
|
|
||||||
@Expose()
|
|
||||||
phoneNumber: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class BookingSpaceResponseDto {
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
uuid: string;
|
|
||||||
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
spaceName: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export class BookingResponseDto {
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
uuid: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: Date,
|
|
||||||
})
|
|
||||||
@Expose()
|
|
||||||
date: Date;
|
|
||||||
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
startTime: string;
|
|
||||||
|
|
||||||
@ApiProperty()
|
|
||||||
@Expose()
|
|
||||||
endTime: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: Number,
|
|
||||||
})
|
|
||||||
@Expose()
|
|
||||||
cost: number;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: BookingUserResponseDto,
|
|
||||||
})
|
|
||||||
@Type(() => BookingUserResponseDto)
|
|
||||||
@Expose()
|
|
||||||
user: BookingUserResponseDto;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: BookingSpaceResponseDto,
|
|
||||||
})
|
|
||||||
@Type(() => BookingSpaceResponseDto)
|
|
||||||
@Expose()
|
|
||||||
space: BookingSpaceResponseDto;
|
|
||||||
}
|
|
@ -1,63 +0,0 @@
|
|||||||
import { DaysEnum } from '@app/common/constants/days.enum';
|
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
|
||||||
import {
|
|
||||||
ArrayMinSize,
|
|
||||||
IsArray,
|
|
||||||
IsEnum,
|
|
||||||
IsInt,
|
|
||||||
IsNotEmpty,
|
|
||||||
IsOptional,
|
|
||||||
IsString,
|
|
||||||
IsUUID,
|
|
||||||
Matches,
|
|
||||||
Max,
|
|
||||||
Min,
|
|
||||||
} from 'class-validator';
|
|
||||||
|
|
||||||
export class CreateBookableSpaceDto {
|
|
||||||
@ApiProperty({
|
|
||||||
type: 'string',
|
|
||||||
isArray: true,
|
|
||||||
example: [
|
|
||||||
'3fa85f64-5717-4562-b3fc-2c963f66afa6',
|
|
||||||
'4fa85f64-5717-4562-b3fc-2c963f66afa7',
|
|
||||||
],
|
|
||||||
})
|
|
||||||
@IsArray()
|
|
||||||
@ArrayMinSize(1, { message: 'At least one space must be selected' })
|
|
||||||
@IsUUID('all', { each: true, message: 'Invalid space UUID provided' })
|
|
||||||
spaceUuids: string[];
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
enum: DaysEnum,
|
|
||||||
isArray: true,
|
|
||||||
example: [DaysEnum.MON, DaysEnum.WED, DaysEnum.FRI],
|
|
||||||
})
|
|
||||||
@IsArray()
|
|
||||||
@ArrayMinSize(1, { message: 'At least one day must be selected' })
|
|
||||||
@IsEnum(DaysEnum, { each: true, message: 'Invalid day provided' })
|
|
||||||
daysAvailable: DaysEnum[];
|
|
||||||
|
|
||||||
@ApiProperty({ example: '09:00' })
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty({ message: 'Start time cannot be empty' })
|
|
||||||
@Matches(/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/, {
|
|
||||||
message: 'Start time must be in HH:mm format (24-hour)',
|
|
||||||
})
|
|
||||||
startTime: string;
|
|
||||||
|
|
||||||
@ApiProperty({ example: '17:00' })
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty({ message: 'End time cannot be empty' })
|
|
||||||
@Matches(/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/, {
|
|
||||||
message: 'End time must be in HH:mm format (24-hour)',
|
|
||||||
})
|
|
||||||
endTime: string;
|
|
||||||
|
|
||||||
@ApiProperty({ example: 10, required: false })
|
|
||||||
@IsOptional()
|
|
||||||
@IsInt()
|
|
||||||
@Min(0, { message: 'Points cannot be negative' })
|
|
||||||
@Max(1000, { message: 'Points cannot exceed 1000' })
|
|
||||||
points?: number;
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
|
||||||
import { IsDate, IsNotEmpty, IsString, IsUUID, Matches } from 'class-validator';
|
|
||||||
|
|
||||||
export class CreateBookingDto {
|
|
||||||
@ApiProperty({
|
|
||||||
type: 'string',
|
|
||||||
example: '4fa85f64-5717-4562-b3fc-2c963f66afa7',
|
|
||||||
})
|
|
||||||
@IsNotEmpty()
|
|
||||||
@IsUUID('4', { message: 'Invalid space UUID provided' })
|
|
||||||
spaceUuid: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
type: Date,
|
|
||||||
})
|
|
||||||
@IsNotEmpty()
|
|
||||||
@IsDate()
|
|
||||||
date: Date;
|
|
||||||
|
|
||||||
@ApiProperty({ example: '09:00' })
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty({ message: 'Start time cannot be empty' })
|
|
||||||
@Matches(/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/, {
|
|
||||||
message: 'Start time must be in HH:mm format (24-hour)',
|
|
||||||
})
|
|
||||||
startTime: string;
|
|
||||||
|
|
||||||
@ApiProperty({ example: '17:00' })
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty({ message: 'End time cannot be empty' })
|
|
||||||
@Matches(/^([01]?[0-9]|2[0-3]):[0-5][0-9]$/, {
|
|
||||||
message: 'End time must be in HH:mm format (24-hour)',
|
|
||||||
})
|
|
||||||
endTime: string;
|
|
||||||
}
|
|
@ -1,14 +0,0 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
|
||||||
import { IsIn, IsOptional } from 'class-validator';
|
|
||||||
|
|
||||||
export class MyBookingRequestDto {
|
|
||||||
@ApiProperty({
|
|
||||||
description: 'Filter bookings by time period',
|
|
||||||
example: 'past',
|
|
||||||
enum: ['past', 'future'],
|
|
||||||
required: false,
|
|
||||||
})
|
|
||||||
@IsOptional()
|
|
||||||
@IsIn(['past', 'future'])
|
|
||||||
when?: 'past' | 'future';
|
|
||||||
}
|
|
@ -1,12 +0,0 @@
|
|||||||
import { ApiProperty, OmitType, PartialType } from '@nestjs/swagger';
|
|
||||||
import { IsBoolean, IsOptional } from 'class-validator';
|
|
||||||
import { CreateBookableSpaceDto } from './create-bookable-space.dto';
|
|
||||||
|
|
||||||
export class UpdateBookableSpaceDto extends PartialType(
|
|
||||||
OmitType(CreateBookableSpaceDto, ['spaceUuids']),
|
|
||||||
) {
|
|
||||||
@ApiProperty({ type: Boolean })
|
|
||||||
@IsOptional()
|
|
||||||
@IsBoolean()
|
|
||||||
active?: boolean;
|
|
||||||
}
|
|
@ -1 +0,0 @@
|
|||||||
export * from './booking.module';
|
|
@ -1,197 +0,0 @@
|
|||||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
|
||||||
import { PageResponseDto } from '@app/common/dto/pagination.response.dto';
|
|
||||||
import { timeToMinutes } from '@app/common/helper/timeToMinutes';
|
|
||||||
import { TypeORMCustomModel } from '@app/common/models/typeOrmCustom.model';
|
|
||||||
import { BookableSpaceEntityRepository } from '@app/common/modules/booking/repositories/bookable-space.repository';
|
|
||||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
|
||||||
import { SpaceRepository } from '@app/common/modules/space/repositories/space.repository';
|
|
||||||
import {
|
|
||||||
BadRequestException,
|
|
||||||
ConflictException,
|
|
||||||
Injectable,
|
|
||||||
NotFoundException,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { In } from 'typeorm';
|
|
||||||
import { BookableSpaceRequestDto } from '../dtos/bookable-space-request.dto';
|
|
||||||
import { CreateBookableSpaceDto } from '../dtos/create-bookable-space.dto';
|
|
||||||
import { UpdateBookableSpaceDto } from '../dtos/update-bookable-space.dto';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class BookableSpaceService {
|
|
||||||
constructor(
|
|
||||||
private readonly bookableSpaceEntityRepository: BookableSpaceEntityRepository,
|
|
||||||
private readonly spaceRepository: SpaceRepository,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
async create(dto: CreateBookableSpaceDto) {
|
|
||||||
// Validate time slots first
|
|
||||||
this.validateTimeSlot(dto.startTime, dto.endTime);
|
|
||||||
|
|
||||||
// fetch spaces exist
|
|
||||||
const spaces = await this.getSpacesOrFindMissing(dto.spaceUuids);
|
|
||||||
|
|
||||||
// Validate no duplicate bookable configurations
|
|
||||||
await this.validateNoDuplicateBookableConfigs(dto.spaceUuids);
|
|
||||||
|
|
||||||
// Create and save bookable spaces
|
|
||||||
return this.createBookableSpaces(spaces, dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
async findAll(
|
|
||||||
{ active, page, size, configured, search }: BookableSpaceRequestDto,
|
|
||||||
project: string,
|
|
||||||
): Promise<{
|
|
||||||
data: BaseResponseDto['data'];
|
|
||||||
pagination: PageResponseDto;
|
|
||||||
}> {
|
|
||||||
let qb = this.spaceRepository
|
|
||||||
.createQueryBuilder('space')
|
|
||||||
.leftJoinAndSelect('space.parent', 'parentSpace')
|
|
||||||
.leftJoinAndSelect('space.community', 'community')
|
|
||||||
.where('community.project = :project', { project });
|
|
||||||
|
|
||||||
if (search) {
|
|
||||||
qb = qb.andWhere(
|
|
||||||
'(space.spaceName ILIKE :search OR community.name ILIKE :search OR parentSpace.spaceName ILIKE :search)',
|
|
||||||
{ search: `%${search}%` },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (configured) {
|
|
||||||
qb = qb
|
|
||||||
.leftJoinAndSelect('space.bookableConfig', 'bookableConfig')
|
|
||||||
.andWhere('bookableConfig.uuid IS NOT NULL');
|
|
||||||
if (active !== undefined) {
|
|
||||||
qb = qb.andWhere('bookableConfig.active = :active', { active });
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
qb = qb
|
|
||||||
.leftJoinAndSelect('space.bookableConfig', 'bookableConfig')
|
|
||||||
.andWhere('bookableConfig.uuid IS NULL');
|
|
||||||
}
|
|
||||||
const customModel = TypeORMCustomModel(this.spaceRepository);
|
|
||||||
|
|
||||||
const { baseResponseDto, paginationResponseDto } =
|
|
||||||
await customModel.findAll({ page, size, modelName: 'space' }, qb);
|
|
||||||
return {
|
|
||||||
data: baseResponseDto.data.map((space) => {
|
|
||||||
return {
|
|
||||||
...space,
|
|
||||||
virtualLocation: `${space.community?.name} - ${space.parent ? space.parent?.spaceName + ' - ' : ''}${space.spaceName}`,
|
|
||||||
};
|
|
||||||
}),
|
|
||||||
pagination: paginationResponseDto,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* todo: if updating availability, send to the ones who have access to this space
|
|
||||||
* todo: if updating other fields, just send emails to all users who's bookings might be affected
|
|
||||||
*/
|
|
||||||
async update(spaceUuid: string, dto: UpdateBookableSpaceDto) {
|
|
||||||
// fetch spaces exist
|
|
||||||
const space = (await this.getSpacesOrFindMissing([spaceUuid]))[0];
|
|
||||||
|
|
||||||
if (!space.bookableConfig) {
|
|
||||||
throw new NotFoundException(
|
|
||||||
`Bookable configuration not found for space: ${spaceUuid}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (dto.startTime || dto.endTime) {
|
|
||||||
// Validate time slots first
|
|
||||||
this.validateTimeSlot(
|
|
||||||
dto.startTime || space.bookableConfig.startTime,
|
|
||||||
dto.endTime || space.bookableConfig.endTime,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Object.assign(space.bookableConfig, dto);
|
|
||||||
return this.bookableSpaceEntityRepository.save(space.bookableConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch spaces by UUIDs and throw an error if any are missing
|
|
||||||
*/
|
|
||||||
private async getSpacesOrFindMissing(
|
|
||||||
spaceUuids: string[],
|
|
||||||
): Promise<SpaceEntity[]> {
|
|
||||||
const spaces = await this.spaceRepository.find({
|
|
||||||
where: { uuid: In(spaceUuids) },
|
|
||||||
relations: ['bookableConfig'],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (spaces.length !== spaceUuids.length) {
|
|
||||||
const foundUuids = spaces.map((s) => s.uuid);
|
|
||||||
const missingUuids = spaceUuids.filter(
|
|
||||||
(uuid) => !foundUuids.includes(uuid),
|
|
||||||
);
|
|
||||||
throw new NotFoundException(
|
|
||||||
`Spaces not found: ${missingUuids.join(', ')}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return spaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate there are no existing bookable configurations for these spaces
|
|
||||||
*/
|
|
||||||
private async validateNoDuplicateBookableConfigs(
|
|
||||||
spaceUuids: string[],
|
|
||||||
): Promise<void> {
|
|
||||||
const existingBookables = await this.bookableSpaceEntityRepository.find({
|
|
||||||
where: { space: { uuid: In(spaceUuids) } },
|
|
||||||
relations: ['space'],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (existingBookables.length > 0) {
|
|
||||||
const existingUuids = [
|
|
||||||
...new Set(existingBookables.map((b) => b.space.uuid)),
|
|
||||||
];
|
|
||||||
throw new ConflictException(
|
|
||||||
`Bookable configuration already exists for spaces: ${existingUuids.join(', ')}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensure the slot start time is before the end time
|
|
||||||
*/
|
|
||||||
private validateTimeSlot(startTime: string, endTime: string): void {
|
|
||||||
const start = timeToMinutes(startTime);
|
|
||||||
const end = timeToMinutes(endTime);
|
|
||||||
|
|
||||||
if (start >= end) {
|
|
||||||
throw new BadRequestException(
|
|
||||||
`End time must be after start time for slot: ${startTime}-${endTime}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create bookable space entries after all validations pass
|
|
||||||
*/
|
|
||||||
private async createBookableSpaces(
|
|
||||||
spaces: SpaceEntity[],
|
|
||||||
dto: CreateBookableSpaceDto,
|
|
||||||
) {
|
|
||||||
try {
|
|
||||||
const entries = spaces.map((space) =>
|
|
||||||
this.bookableSpaceEntityRepository.create({
|
|
||||||
space,
|
|
||||||
daysAvailable: dto.daysAvailable,
|
|
||||||
startTime: dto.startTime,
|
|
||||||
endTime: dto.endTime,
|
|
||||||
points: dto.points,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
return this.bookableSpaceEntityRepository.save(entries);
|
|
||||||
} catch (error) {
|
|
||||||
if (error.code === '23505') {
|
|
||||||
throw new ConflictException(
|
|
||||||
'Duplicate bookable space configuration detected',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,192 +0,0 @@
|
|||||||
import { DaysEnum } from '@app/common/constants/days.enum';
|
|
||||||
import { timeToMinutes } from '@app/common/helper/timeToMinutes';
|
|
||||||
import { BookingEntityRepository } from '@app/common/modules/booking/repositories/booking.repository';
|
|
||||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
|
||||||
import { SpaceRepository } from '@app/common/modules/space/repositories/space.repository';
|
|
||||||
import { UserRepository } from '@app/common/modules/user/repositories/user.repository';
|
|
||||||
import {
|
|
||||||
BadRequestException,
|
|
||||||
ConflictException,
|
|
||||||
ForbiddenException,
|
|
||||||
Injectable,
|
|
||||||
NotFoundException,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import { Between } from 'typeorm/find-options/operator/Between';
|
|
||||||
import { BookingRequestDto } from '../dtos/booking-request.dto';
|
|
||||||
import { CreateBookingDto } from '../dtos/create-booking.dto';
|
|
||||||
import { MyBookingRequestDto } from '../dtos/my-booking-request.dto';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class BookingService {
|
|
||||||
constructor(
|
|
||||||
private readonly bookingEntityRepository: BookingEntityRepository,
|
|
||||||
private readonly spaceRepository: SpaceRepository,
|
|
||||||
private readonly userRepository: UserRepository,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
async create(userUuid: string, dto: CreateBookingDto) {
|
|
||||||
console.log(userUuid);
|
|
||||||
const user = await this.userRepository.findOne({
|
|
||||||
where: { uuid: userUuid },
|
|
||||||
relations: ['userSpaces', 'userSpaces.space'],
|
|
||||||
});
|
|
||||||
console.log(user.userSpaces);
|
|
||||||
if (!user.userSpaces.some(({ space }) => space.uuid === dto.spaceUuid)) {
|
|
||||||
throw new ForbiddenException(
|
|
||||||
`User does not have permission to book this space: ${dto.spaceUuid}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// Validate time slots first
|
|
||||||
this.validateTimeSlot(dto.startTime, dto.endTime);
|
|
||||||
|
|
||||||
// fetch spaces exist
|
|
||||||
const space = await this.getSpaceConfigurationAndBookings(dto.spaceUuid);
|
|
||||||
|
|
||||||
// Validate booking availability
|
|
||||||
this.validateBookingAvailability(space, dto);
|
|
||||||
|
|
||||||
// Create and save booking
|
|
||||||
return this.createBookings(space, userUuid, dto);
|
|
||||||
}
|
|
||||||
|
|
||||||
async findAll({ month }: BookingRequestDto, project: string) {
|
|
||||||
const [monthNumber, year] = month.split('/').map(Number);
|
|
||||||
const fromDate = new Date(year, monthNumber - 1, 1);
|
|
||||||
const toDate = new Date(year, monthNumber, 0, 23, 59, 59);
|
|
||||||
return this.bookingEntityRepository.find({
|
|
||||||
where: {
|
|
||||||
space: { community: { project: { uuid: project } } },
|
|
||||||
date: Between(fromDate, toDate),
|
|
||||||
},
|
|
||||||
relations: ['space', 'user', 'user.inviteUser'],
|
|
||||||
order: { date: 'DESC' },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async findMyBookings(
|
|
||||||
{ when }: MyBookingRequestDto,
|
|
||||||
userUuid: string,
|
|
||||||
project: string,
|
|
||||||
) {
|
|
||||||
return this.bookingEntityRepository.find({
|
|
||||||
where: {
|
|
||||||
user: { uuid: userUuid },
|
|
||||||
space: { community: { project: { uuid: project } } },
|
|
||||||
// date: when
|
|
||||||
// ? when === 'past'
|
|
||||||
// ? LessThanOrEqual(new Date())
|
|
||||||
// : MoreThanOrEqual(new Date())
|
|
||||||
// : undefined,
|
|
||||||
},
|
|
||||||
relations: ['space', 'user'],
|
|
||||||
order: { date: 'DESC' },
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch space by UUID and throw an error if not found or if not configured for booking
|
|
||||||
*/
|
|
||||||
private async getSpaceConfigurationAndBookings(
|
|
||||||
spaceUuid: string,
|
|
||||||
): Promise<SpaceEntity> {
|
|
||||||
const space = await this.spaceRepository.findOne({
|
|
||||||
where: { uuid: spaceUuid },
|
|
||||||
relations: ['bookableConfig', 'bookings'],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!space) {
|
|
||||||
throw new NotFoundException(`Space not found: ${spaceUuid}`);
|
|
||||||
}
|
|
||||||
if (!space.bookableConfig) {
|
|
||||||
throw new NotFoundException(
|
|
||||||
`This space is not configured for booking: ${spaceUuid}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return space;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Ensure the slot start time is before the end time
|
|
||||||
*/
|
|
||||||
private validateTimeSlot(startTime: string, endTime: string): void {
|
|
||||||
const start = timeToMinutes(startTime);
|
|
||||||
const end = timeToMinutes(endTime);
|
|
||||||
|
|
||||||
if (start >= end) {
|
|
||||||
throw new BadRequestException(
|
|
||||||
`End time must be after start time for slot: ${startTime}-${endTime}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* check if the space is available for booking on the requested day
|
|
||||||
* and if the requested time slot is within the available hours
|
|
||||||
*/
|
|
||||||
private validateBookingAvailability(
|
|
||||||
space: SpaceEntity,
|
|
||||||
dto: CreateBookingDto,
|
|
||||||
): void {
|
|
||||||
// Check if the space is available for booking on the requested day
|
|
||||||
const availableDays = space.bookableConfig?.daysAvailable || [];
|
|
||||||
const requestedDay = new Date(dto.date).toLocaleDateString('en-US', {
|
|
||||||
weekday: 'short',
|
|
||||||
}) as DaysEnum;
|
|
||||||
|
|
||||||
if (!availableDays.includes(requestedDay)) {
|
|
||||||
const dayFullName = new Date(dto.date).toLocaleDateString('en-US', {
|
|
||||||
weekday: 'long',
|
|
||||||
});
|
|
||||||
throw new BadRequestException(
|
|
||||||
`Space is not available for booking on ${dayFullName}s`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const dtoStartTimeInMinutes = timeToMinutes(dto.startTime);
|
|
||||||
const dtoEndTimeInMinutes = timeToMinutes(dto.endTime);
|
|
||||||
|
|
||||||
if (
|
|
||||||
dtoStartTimeInMinutes < timeToMinutes(space.bookableConfig.startTime) ||
|
|
||||||
dtoEndTimeInMinutes > timeToMinutes(space.bookableConfig.endTime)
|
|
||||||
) {
|
|
||||||
throw new BadRequestException(
|
|
||||||
`Booking time must be within the available hours for space: ${space.spaceName}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const previousBookings = space.bookings.filter(
|
|
||||||
(booking) =>
|
|
||||||
timeToMinutes(booking.startTime) < dtoEndTimeInMinutes &&
|
|
||||||
timeToMinutes(booking.endTime) > dtoStartTimeInMinutes,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (previousBookings.length > 0) {
|
|
||||||
// tell the user what time is unavailable
|
|
||||||
const unavailableTimes = previousBookings.map((booking) => {
|
|
||||||
return `${booking.startTime}-${booking.endTime}`;
|
|
||||||
});
|
|
||||||
throw new ConflictException(
|
|
||||||
`Space is already booked during this times: ${unavailableTimes.join(', ')}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Create bookable space entries after all validations pass
|
|
||||||
*/
|
|
||||||
private async createBookings(
|
|
||||||
space: SpaceEntity,
|
|
||||||
user: string,
|
|
||||||
{ spaceUuid, date, ...dto }: CreateBookingDto,
|
|
||||||
) {
|
|
||||||
const entry = this.bookingEntityRepository.create({
|
|
||||||
space: { uuid: spaceUuid },
|
|
||||||
user: { uuid: user },
|
|
||||||
...dto,
|
|
||||||
date: new Date(date),
|
|
||||||
cost: space.bookableConfig?.points || null,
|
|
||||||
});
|
|
||||||
|
|
||||||
return this.bookingEntityRepository.save(entry);
|
|
||||||
}
|
|
||||||
}
|
|
@ -5,6 +5,7 @@ import { ConfigModule } from '@nestjs/config';
|
|||||||
import { SpaceRepositoryModule } from '@app/common/modules/space/space.repository.module';
|
import { SpaceRepositoryModule } from '@app/common/modules/space/space.repository.module';
|
||||||
import {
|
import {
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
|
SpaceLinkRepository,
|
||||||
SpaceProductAllocationRepository,
|
SpaceProductAllocationRepository,
|
||||||
SpaceRepository,
|
SpaceRepository,
|
||||||
} from '@app/common/modules/space/repositories';
|
} from '@app/common/modules/space/repositories';
|
||||||
@ -15,12 +16,14 @@ import { CommunityRepository } from '@app/common/modules/community/repositories'
|
|||||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||||
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||||
import {
|
import {
|
||||||
|
SpaceLinkService,
|
||||||
SpaceService,
|
SpaceService,
|
||||||
SubspaceDeviceService,
|
SubspaceDeviceService,
|
||||||
SubSpaceService,
|
SubSpaceService,
|
||||||
ValidationService,
|
ValidationService,
|
||||||
} from 'src/space/services';
|
} from 'src/space/services';
|
||||||
import { TagService as NewTagService } from 'src/tags/services';
|
import { TagService as NewTagService } from 'src/tags/services';
|
||||||
|
import { TagService } from 'src/space/services/tag';
|
||||||
import {
|
import {
|
||||||
SpaceModelService,
|
SpaceModelService,
|
||||||
SubSpaceModelService,
|
SubSpaceModelService,
|
||||||
@ -78,13 +81,16 @@ import { AqiSpaceDailyPollutantStatsRepository } from '@app/common/modules/aqi/r
|
|||||||
SpaceService,
|
SpaceService,
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
// Todo: find out why this is needed
|
// Todo: find out why this is needed
|
||||||
|
SpaceLinkService,
|
||||||
SubSpaceService,
|
SubSpaceService,
|
||||||
ValidationService,
|
ValidationService,
|
||||||
NewTagService,
|
NewTagService,
|
||||||
SpaceModelService,
|
SpaceModelService,
|
||||||
SpaceProductAllocationService,
|
SpaceProductAllocationService,
|
||||||
|
SpaceLinkRepository,
|
||||||
SubspaceRepository,
|
SubspaceRepository,
|
||||||
// Todo: find out why this is needed
|
// Todo: find out why this is needed
|
||||||
|
TagService,
|
||||||
SubspaceDeviceService,
|
SubspaceDeviceService,
|
||||||
SubspaceProductAllocationService,
|
SubspaceProductAllocationService,
|
||||||
SpaceModelRepository,
|
SpaceModelRepository,
|
||||||
|
@ -120,7 +120,6 @@ 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(
|
||||||
@ -210,7 +209,7 @@ export class CommunityService {
|
|||||||
if (search) {
|
if (search) {
|
||||||
qb.andWhere(
|
qb.andWhere(
|
||||||
`c.name ILIKE :search ${includeSpaces ? 'OR space.space_name ILIKE :search' : ''}`,
|
`c.name ILIKE :search ${includeSpaces ? 'OR space.space_name ILIKE :search' : ''}`,
|
||||||
{ search: `%${search}%` },
|
{ search },
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,41 +1,39 @@
|
|||||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
import { DeviceService } from '../services/device.service';
|
||||||
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,
|
||||||
Delete,
|
|
||||||
Get,
|
Get,
|
||||||
Param,
|
|
||||||
Post,
|
Post,
|
||||||
Put,
|
|
||||||
Query,
|
Query,
|
||||||
Req,
|
Param,
|
||||||
UnauthorizedException,
|
|
||||||
UseGuards,
|
UseGuards,
|
||||||
|
Put,
|
||||||
|
Delete,
|
||||||
|
Req,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||||
import { Permissions } from 'src/decorators/permissions.decorator';
|
|
||||||
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
|
||||||
import { CheckRoomGuard } from 'src/guards/room.guard';
|
|
||||||
import { CheckFourAndSixSceneDeviceTypeGuard } from 'src/guards/scene.device.type.guard';
|
|
||||||
import {
|
import {
|
||||||
AddDeviceDto,
|
AddDeviceDto,
|
||||||
AddSceneToFourSceneDeviceDto,
|
AddSceneToFourSceneDeviceDto,
|
||||||
AssignDeviceToSpaceDto,
|
AssignDeviceToSpaceDto,
|
||||||
UpdateDeviceDto,
|
UpdateDeviceDto,
|
||||||
} from '../dtos/add.device.dto';
|
} from '../dtos/add.device.dto';
|
||||||
|
import { GetDeviceLogsDto } from '../dtos/get.device.dto';
|
||||||
import {
|
import {
|
||||||
|
ControlDeviceDto,
|
||||||
BatchControlDevicesDto,
|
BatchControlDevicesDto,
|
||||||
BatchStatusDevicesDto,
|
BatchStatusDevicesDto,
|
||||||
ControlDeviceDto,
|
|
||||||
GetSceneFourSceneDeviceDto,
|
GetSceneFourSceneDeviceDto,
|
||||||
} from '../dtos/control.device.dto';
|
} from '../dtos/control.device.dto';
|
||||||
import { DeleteSceneFromSceneDeviceDto } from '../dtos/delete.device.dto';
|
import { CheckRoomGuard } from 'src/guards/room.guard';
|
||||||
|
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||||
|
import { CheckFourAndSixSceneDeviceTypeGuard } from 'src/guards/scene.device.type.guard';
|
||||||
|
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||||
|
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||||
import { DeviceSceneParamDto } from '../dtos/device.param.dto';
|
import { DeviceSceneParamDto } from '../dtos/device.param.dto';
|
||||||
import { GetDeviceLogsDto } from '../dtos/get.device.dto';
|
import { DeleteSceneFromSceneDeviceDto } from '../dtos/delete.device.dto';
|
||||||
import { DeviceService } from '../services/device.service';
|
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
||||||
|
import { Permissions } from 'src/decorators/permissions.decorator';
|
||||||
|
|
||||||
@ApiTags('Device Module')
|
@ApiTags('Device Module')
|
||||||
@Controller({
|
@Controller({
|
||||||
@ -342,22 +340,4 @@ export class DeviceController {
|
|||||||
projectUuid,
|
projectUuid,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
|
||||||
@UseGuards(PermissionsGuard)
|
|
||||||
@Permissions('DEVICE_UPDATE')
|
|
||||||
@Post('/populate-tuya-const-uuids')
|
|
||||||
@ApiOperation({
|
|
||||||
summary: ControllerRoute.DEVICE.ACTIONS.POPULATE_TUYA_CONST_UUID_SUMMARY,
|
|
||||||
description:
|
|
||||||
ControllerRoute.DEVICE.ACTIONS.POPULATE_TUYA_CONST_UUID_DESCRIPTION,
|
|
||||||
})
|
|
||||||
async populateTuyaConstUuid(@Req() req: any): Promise<void> {
|
|
||||||
const userUuid = req['user']?.userUuid;
|
|
||||||
const userRole = req['user']?.role;
|
|
||||||
if (!userUuid || (userRole && userRole !== RoleType.SUPER_ADMIN)) {
|
|
||||||
throw new UnauthorizedException('Unauthorized to perform this action');
|
|
||||||
}
|
|
||||||
return this.deviceService.addTuyaConstUuidToDevices();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -18,14 +18,6 @@ export class AddDeviceDto {
|
|||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
public spaceUuid: string;
|
public spaceUuid: string;
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
description: 'tagUuid',
|
|
||||||
required: true,
|
|
||||||
})
|
|
||||||
@IsString()
|
|
||||||
@IsNotEmpty()
|
|
||||||
public tagUuid: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'deviceName',
|
description: 'deviceName',
|
||||||
required: true,
|
required: true,
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { DeviceTypeEnum } from '@app/common/constants/device-type.enum';
|
import { DeviceTypeEnum } from '@app/common/constants/device-type.enum';
|
||||||
import { ApiProperty } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { Transform } from 'class-transformer';
|
|
||||||
import {
|
import {
|
||||||
|
IsArray,
|
||||||
IsEnum,
|
IsEnum,
|
||||||
IsNotEmpty,
|
IsNotEmpty,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
@ -74,34 +74,13 @@ export class GetDevicesFilterDto {
|
|||||||
@IsEnum(DeviceTypeEnum)
|
@IsEnum(DeviceTypeEnum)
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
public deviceType: DeviceTypeEnum;
|
public deviceType: DeviceTypeEnum;
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'List of Space IDs to filter devices',
|
description: 'List of Space IDs to filter devices',
|
||||||
required: false,
|
required: false,
|
||||||
example: ['60d21b4667d0d8992e610c85', '60d21b4967d0d8992e610c86'],
|
example: ['60d21b4667d0d8992e610c85', '60d21b4967d0d8992e610c86'],
|
||||||
})
|
})
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@Transform(({ value }) => {
|
@IsArray()
|
||||||
if (!Array.isArray(value)) {
|
|
||||||
return [value];
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
})
|
|
||||||
@IsUUID('4', { each: true })
|
@IsUUID('4', { each: true })
|
||||||
public spaces?: string[];
|
public spaces?: string[];
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
description: 'List of Community IDs to filter devices',
|
|
||||||
required: false,
|
|
||||||
example: ['60d21b4667d0d8992e610c85', '60d21b4967d0d8992e610c86'],
|
|
||||||
})
|
|
||||||
@Transform(({ value }) => {
|
|
||||||
if (!Array.isArray(value)) {
|
|
||||||
return [value];
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
})
|
|
||||||
@IsOptional()
|
|
||||||
@IsUUID('4', { each: true })
|
|
||||||
public communities?: string[];
|
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -5,7 +5,6 @@ import {
|
|||||||
IsNotEmpty,
|
IsNotEmpty,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
IsString,
|
IsString,
|
||||||
IsUUID,
|
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
|
|
||||||
export class AddUserInvitationDto {
|
export class AddUserInvitationDto {
|
||||||
@ -45,15 +44,6 @@ export class AddUserInvitationDto {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
public jobTitle?: string;
|
public jobTitle?: string;
|
||||||
|
|
||||||
@ApiProperty({
|
|
||||||
description: 'The company name of the user',
|
|
||||||
example: 'Tech Corp',
|
|
||||||
required: false,
|
|
||||||
})
|
|
||||||
@IsString()
|
|
||||||
@IsOptional()
|
|
||||||
public companyName?: string;
|
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'The phone number of the user',
|
description: 'The phone number of the user',
|
||||||
example: '+1234567890',
|
example: '+1234567890',
|
||||||
@ -68,7 +58,7 @@ export class AddUserInvitationDto {
|
|||||||
example: 'd290f1ee-6c54-4b01-90e6-d701748f0851',
|
example: 'd290f1ee-6c54-4b01-90e6-d701748f0851',
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
@IsUUID('4')
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
public roleUuid: string;
|
public roleUuid: string;
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
@ -76,17 +66,15 @@ export class AddUserInvitationDto {
|
|||||||
example: 'd290f1ee-6c54-4b01-90e6-d701748f0851',
|
example: 'd290f1ee-6c54-4b01-90e6-d701748f0851',
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
@IsUUID('4')
|
@IsString()
|
||||||
@IsNotEmpty()
|
@IsNotEmpty()
|
||||||
public projectUuid: string;
|
public projectUuid: string;
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'The array of space UUIDs (at least one required)',
|
description: 'The array of space UUIDs (at least one required)',
|
||||||
example: ['b5f3c9d2-58b7-4377-b3f7-60acb711d5d9'],
|
example: ['b5f3c9d2-58b7-4377-b3f7-60acb711d5d9'],
|
||||||
required: true,
|
required: true,
|
||||||
})
|
})
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@IsUUID('4', { each: true })
|
|
||||||
@ArrayMinSize(1)
|
@ArrayMinSize(1)
|
||||||
public spaceUuids: string[];
|
public spaceUuids: string[];
|
||||||
constructor(dto: Partial<AddUserInvitationDto>) {
|
constructor(dto: Partial<AddUserInvitationDto>) {
|
||||||
|
@ -1,10 +1,78 @@
|
|||||||
import { ApiProperty, OmitType } from '@nestjs/swagger';
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
import { IsBoolean, IsNotEmpty, IsString } from 'class-validator';
|
import {
|
||||||
import { AddUserInvitationDto } from './add.invite-user.dto';
|
ArrayMinSize,
|
||||||
|
IsArray,
|
||||||
|
IsBoolean,
|
||||||
|
IsNotEmpty,
|
||||||
|
IsOptional,
|
||||||
|
IsString,
|
||||||
|
} from 'class-validator';
|
||||||
|
|
||||||
export class UpdateUserInvitationDto extends OmitType(AddUserInvitationDto, [
|
export class UpdateUserInvitationDto {
|
||||||
'email',
|
@ApiProperty({
|
||||||
]) {}
|
description: 'The first name of the user',
|
||||||
|
example: 'John',
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
public firstName: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The last name of the user',
|
||||||
|
example: 'Doe',
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
public lastName: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The job title of the user',
|
||||||
|
example: 'Software Engineer',
|
||||||
|
required: false,
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
public jobTitle?: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The phone number of the user',
|
||||||
|
example: '+1234567890',
|
||||||
|
required: false,
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
@IsOptional()
|
||||||
|
public phoneNumber?: string;
|
||||||
|
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The role uuid of the user',
|
||||||
|
example: 'd290f1ee-6c54-4b01-90e6-d701748f0851',
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
public roleUuid: string;
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The project uuid of the user',
|
||||||
|
example: 'd290f1ee-6c54-4b01-90e6-d701748f0851',
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
public projectUuid: string;
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'The array of space UUIDs (at least one required)',
|
||||||
|
example: ['b5f3c9d2-58b7-4377-b3f7-60acb711d5d9'],
|
||||||
|
required: true,
|
||||||
|
})
|
||||||
|
@IsArray()
|
||||||
|
@ArrayMinSize(1)
|
||||||
|
public spaceUuids: string[];
|
||||||
|
constructor(dto: Partial<UpdateUserInvitationDto>) {
|
||||||
|
Object.assign(this, dto);
|
||||||
|
}
|
||||||
|
}
|
||||||
export class DisableUserInvitationDto {
|
export class DisableUserInvitationDto {
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'The disable status of the user',
|
description: 'The disable status of the user',
|
||||||
|
@ -38,6 +38,7 @@ import {
|
|||||||
} from '@app/common/modules/scene/repositories';
|
} from '@app/common/modules/scene/repositories';
|
||||||
import {
|
import {
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
|
SpaceLinkRepository,
|
||||||
SpaceProductAllocationRepository,
|
SpaceProductAllocationRepository,
|
||||||
SpaceRepository,
|
SpaceRepository,
|
||||||
} from '@app/common/modules/space';
|
} from '@app/common/modules/space';
|
||||||
@ -120,6 +121,7 @@ import { AqiSpaceDailyPollutantStatsRepository } from '@app/common/modules/aqi/r
|
|||||||
NewTagService,
|
NewTagService,
|
||||||
SpaceModelService,
|
SpaceModelService,
|
||||||
SpaceProductAllocationService,
|
SpaceProductAllocationService,
|
||||||
|
SpaceLinkRepository,
|
||||||
SubspaceRepository,
|
SubspaceRepository,
|
||||||
SubspaceDeviceService,
|
SubspaceDeviceService,
|
||||||
SubspaceProductAllocationService,
|
SubspaceProductAllocationService,
|
||||||
|
@ -8,8 +8,6 @@ import {
|
|||||||
InviteUserRepository,
|
InviteUserRepository,
|
||||||
InviteUserSpaceRepository,
|
InviteUserSpaceRepository,
|
||||||
} from '@app/common/modules/Invite-user/repositiories';
|
} from '@app/common/modules/Invite-user/repositiories';
|
||||||
import { ProjectEntity } from '@app/common/modules/project/entities';
|
|
||||||
import { RoleTypeEntity } from '@app/common/modules/role-type/entities';
|
|
||||||
import { RoleTypeRepository } from '@app/common/modules/role-type/repositories';
|
import { RoleTypeRepository } from '@app/common/modules/role-type/repositories';
|
||||||
import { SpaceRepository } from '@app/common/modules/space';
|
import { SpaceRepository } from '@app/common/modules/space';
|
||||||
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
import { SpaceEntity } from '@app/common/modules/space/entities/space.entity';
|
||||||
@ -63,7 +61,6 @@ export class InviteUserService {
|
|||||||
lastName,
|
lastName,
|
||||||
email,
|
email,
|
||||||
jobTitle,
|
jobTitle,
|
||||||
companyName,
|
|
||||||
phoneNumber,
|
phoneNumber,
|
||||||
roleUuid,
|
roleUuid,
|
||||||
spaceUuids,
|
spaceUuids,
|
||||||
@ -93,8 +90,6 @@ export class InviteUserService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.checkRole(roleUuid, queryRunner);
|
|
||||||
await this.checkProject(projectUuid, queryRunner);
|
|
||||||
// Validate spaces
|
// Validate spaces
|
||||||
const validSpaces = await this.validateSpaces(
|
const validSpaces = await this.validateSpaces(
|
||||||
spaceUuids,
|
spaceUuids,
|
||||||
@ -107,7 +102,6 @@ export class InviteUserService {
|
|||||||
lastName,
|
lastName,
|
||||||
email,
|
email,
|
||||||
jobTitle,
|
jobTitle,
|
||||||
companyName,
|
|
||||||
phoneNumber,
|
phoneNumber,
|
||||||
roleType: { uuid: roleUuid },
|
roleType: { uuid: roleUuid },
|
||||||
status: UserStatusEnum.INVITED,
|
status: UserStatusEnum.INVITED,
|
||||||
@ -117,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) => {
|
||||||
@ -135,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,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -163,6 +156,185 @@ export class InviteUserService {
|
|||||||
await queryRunner.release();
|
await queryRunner.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private async validateSpaces(
|
||||||
|
spaceUuids: string[],
|
||||||
|
entityManager: EntityManager,
|
||||||
|
): Promise<SpaceEntity[]> {
|
||||||
|
const spaceRepo = entityManager.getRepository(SpaceEntity);
|
||||||
|
|
||||||
|
const validSpaces = await spaceRepo.find({
|
||||||
|
where: { uuid: In(spaceUuids) },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (validSpaces.length !== spaceUuids.length) {
|
||||||
|
const validSpaceUuids = validSpaces.map((space) => space.uuid);
|
||||||
|
const invalidSpaceUuids = spaceUuids.filter(
|
||||||
|
(uuid) => !validSpaceUuids.includes(uuid),
|
||||||
|
);
|
||||||
|
throw new HttpException(
|
||||||
|
`Invalid space UUIDs: ${invalidSpaceUuids.join(', ')}`,
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return validSpaces;
|
||||||
|
}
|
||||||
|
|
||||||
|
async checkEmailAndProject(dto: CheckEmailDto): Promise<BaseResponseDto> {
|
||||||
|
const { email } = dto;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const user = await this.userRepository.findOne({
|
||||||
|
where: { email },
|
||||||
|
relations: ['project'],
|
||||||
|
});
|
||||||
|
this.validateUserOrInvite(user, 'User');
|
||||||
|
const invitedUser = await this.inviteUserRepository.findOne({
|
||||||
|
where: { email },
|
||||||
|
relations: ['project'],
|
||||||
|
});
|
||||||
|
this.validateUserOrInvite(invitedUser, 'Invited User');
|
||||||
|
|
||||||
|
return new SuccessResponseDto({
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
success: true,
|
||||||
|
message: 'Valid email',
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error checking email and project:', error);
|
||||||
|
throw new HttpException(
|
||||||
|
error.message ||
|
||||||
|
'An unexpected error occurred while checking the email',
|
||||||
|
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private validateUserOrInvite(user: any, userType: string): void {
|
||||||
|
if (user) {
|
||||||
|
if (!user.isActive) {
|
||||||
|
throw new HttpException(
|
||||||
|
`${userType} is deleted`,
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (user.project) {
|
||||||
|
throw new HttpException(
|
||||||
|
`${userType} already has a project`,
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async activationCode(dto: ActivateCodeDto): Promise<BaseResponseDto> {
|
||||||
|
const { activationCode, userUuid } = dto;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const user = await this.getUser(userUuid);
|
||||||
|
|
||||||
|
const invitedUser = await this.inviteUserRepository.findOne({
|
||||||
|
where: {
|
||||||
|
email: user.email,
|
||||||
|
status: UserStatusEnum.INVITED,
|
||||||
|
isActive: true,
|
||||||
|
},
|
||||||
|
relations: ['project', 'spaces.space.community', 'roleType'],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (invitedUser) {
|
||||||
|
if (invitedUser.invitationCode !== activationCode) {
|
||||||
|
throw new HttpException(
|
||||||
|
'Invalid activation code',
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle invited user with valid activation code
|
||||||
|
await this.handleInvitedUser(user, invitedUser);
|
||||||
|
} else {
|
||||||
|
// Handle case for non-invited user
|
||||||
|
await this.handleNonInvitedUser(activationCode, userUuid);
|
||||||
|
}
|
||||||
|
return new SuccessResponseDto({
|
||||||
|
statusCode: HttpStatus.OK,
|
||||||
|
success: true,
|
||||||
|
message: 'The code has been successfully activated',
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error activating the code:', error);
|
||||||
|
throw new HttpException(
|
||||||
|
error.message ||
|
||||||
|
'An unexpected error occurred while activating the code',
|
||||||
|
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async getUser(userUuid: string): Promise<UserEntity> {
|
||||||
|
const user = await this.userRepository.findOne({
|
||||||
|
where: { uuid: userUuid, isActive: true, isUserVerified: true },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!user) {
|
||||||
|
throw new HttpException('User not found', HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
return user;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleNonInvitedUser(
|
||||||
|
activationCode: string,
|
||||||
|
userUuid: string,
|
||||||
|
): Promise<void> {
|
||||||
|
await this.userSpaceService.verifyCodeAndAddUserSpace(
|
||||||
|
{ inviteCode: activationCode },
|
||||||
|
userUuid,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async handleInvitedUser(
|
||||||
|
user: UserEntity,
|
||||||
|
invitedUser: InviteUserEntity,
|
||||||
|
): Promise<void> {
|
||||||
|
for (const invitedSpace of invitedUser.spaces) {
|
||||||
|
try {
|
||||||
|
const deviceUUIDs = await this.userSpaceService.getDeviceUUIDsForSpace(
|
||||||
|
invitedSpace.space.uuid,
|
||||||
|
);
|
||||||
|
|
||||||
|
await this.userSpaceService.addUserPermissionsToDevices(
|
||||||
|
user.uuid,
|
||||||
|
deviceUUIDs,
|
||||||
|
);
|
||||||
|
|
||||||
|
await this.spaceUserService.associateUserToSpace({
|
||||||
|
communityUuid: invitedSpace.space.community.uuid,
|
||||||
|
spaceUuid: invitedSpace.space.uuid,
|
||||||
|
userUuid: user.uuid,
|
||||||
|
projectUuid: invitedUser.project.uuid,
|
||||||
|
});
|
||||||
|
} catch (spaceError) {
|
||||||
|
console.error(
|
||||||
|
`Error processing space ${invitedSpace.space.uuid}:`,
|
||||||
|
spaceError,
|
||||||
|
);
|
||||||
|
continue; // Skip to the next space
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update invited user and associated user data
|
||||||
|
await this.inviteUserRepository.update(
|
||||||
|
{ uuid: invitedUser.uuid },
|
||||||
|
{ status: UserStatusEnum.ACTIVE, user: { uuid: user.uuid } },
|
||||||
|
);
|
||||||
|
await this.userRepository.update(
|
||||||
|
{ uuid: user.uuid },
|
||||||
|
{
|
||||||
|
project: { uuid: invitedUser.project.uuid },
|
||||||
|
roleType: { uuid: invitedUser.roleType.uuid },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async updateUserInvitation(
|
async updateUserInvitation(
|
||||||
dto: UpdateUserInvitationDto,
|
dto: UpdateUserInvitationDto,
|
||||||
@ -184,9 +356,6 @@ export class InviteUserService {
|
|||||||
throw new HttpException('User not found', HttpStatus.NOT_FOUND);
|
throw new HttpException('User not found', HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.checkRole(dto.roleUuid, queryRunner);
|
|
||||||
await this.checkProject(projectUuid, queryRunner);
|
|
||||||
|
|
||||||
// Perform update actions if status is 'INVITED'
|
// Perform update actions if status is 'INVITED'
|
||||||
if (userOldData.status === UserStatusEnum.INVITED) {
|
if (userOldData.status === UserStatusEnum.INVITED) {
|
||||||
await this.updateWhenUserIsInvite(queryRunner, dto, invitedUserUuid);
|
await this.updateWhenUserIsInvite(queryRunner, dto, invitedUserUuid);
|
||||||
@ -269,7 +438,174 @@ export class InviteUserService {
|
|||||||
await queryRunner.release();
|
await queryRunner.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private async getRoleTypeByUuid(roleUuid: string) {
|
||||||
|
const role = await this.roleTypeRepository.findOne({
|
||||||
|
where: { uuid: roleUuid },
|
||||||
|
});
|
||||||
|
|
||||||
|
return role.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async updateWhenUserIsInvite(
|
||||||
|
queryRunner: QueryRunner,
|
||||||
|
dto: UpdateUserInvitationDto,
|
||||||
|
invitedUserUuid: string,
|
||||||
|
): Promise<void> {
|
||||||
|
const { firstName, lastName, jobTitle, phoneNumber, roleUuid, spaceUuids } =
|
||||||
|
dto;
|
||||||
|
|
||||||
|
// Update user invitation details
|
||||||
|
await queryRunner.manager.update(
|
||||||
|
this.inviteUserRepository.target,
|
||||||
|
{ uuid: invitedUserUuid },
|
||||||
|
{
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
jobTitle,
|
||||||
|
phoneNumber,
|
||||||
|
roleType: { uuid: roleUuid },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Remove old space associations
|
||||||
|
await queryRunner.manager.delete(this.inviteUserSpaceRepository.target, {
|
||||||
|
inviteUser: { uuid: invitedUserUuid },
|
||||||
|
});
|
||||||
|
|
||||||
|
// Save new space associations
|
||||||
|
const spaceData = spaceUuids.map((spaceUuid) => ({
|
||||||
|
inviteUser: { uuid: invitedUserUuid },
|
||||||
|
space: { uuid: spaceUuid },
|
||||||
|
}));
|
||||||
|
await queryRunner.manager.save(
|
||||||
|
this.inviteUserSpaceRepository.target,
|
||||||
|
spaceData,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
private async updateWhenUserIsActive(
|
||||||
|
queryRunner: QueryRunner,
|
||||||
|
dto: UpdateUserInvitationDto,
|
||||||
|
invitedUserUuid: string,
|
||||||
|
): Promise<void> {
|
||||||
|
const {
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
jobTitle,
|
||||||
|
phoneNumber,
|
||||||
|
roleUuid,
|
||||||
|
spaceUuids,
|
||||||
|
projectUuid,
|
||||||
|
} = dto;
|
||||||
|
|
||||||
|
const userData = await this.inviteUserRepository.findOne({
|
||||||
|
where: { uuid: invitedUserUuid },
|
||||||
|
relations: ['user.userSpaces.space', 'user.userSpaces.space.community'],
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!userData) {
|
||||||
|
throw new HttpException(
|
||||||
|
`User with invitedUserUuid ${invitedUserUuid} not found`,
|
||||||
|
HttpStatus.NOT_FOUND,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update user details
|
||||||
|
await queryRunner.manager.update(
|
||||||
|
this.inviteUserRepository.target,
|
||||||
|
{ uuid: invitedUserUuid },
|
||||||
|
{
|
||||||
|
firstName,
|
||||||
|
lastName,
|
||||||
|
jobTitle,
|
||||||
|
phoneNumber,
|
||||||
|
roleType: { uuid: roleUuid },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
await this.userRepository.update(
|
||||||
|
{ uuid: userData.user.uuid },
|
||||||
|
{
|
||||||
|
roleType: { uuid: roleUuid },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
// Disassociate the user from all current spaces
|
||||||
|
const disassociatePromises = userData.user.userSpaces.map((userSpace) =>
|
||||||
|
this.spaceUserService
|
||||||
|
.disassociateUserFromSpace({
|
||||||
|
communityUuid: userSpace.space.community.uuid,
|
||||||
|
spaceUuid: userSpace.space.uuid,
|
||||||
|
userUuid: userData.user.uuid,
|
||||||
|
projectUuid,
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.error(
|
||||||
|
`Failed to disassociate user from space ${userSpace.space.uuid}:`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
throw error;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
await Promise.allSettled(disassociatePromises);
|
||||||
|
|
||||||
|
// Process new spaces
|
||||||
|
const associatePromises = spaceUuids.map(async (spaceUuid) => {
|
||||||
|
try {
|
||||||
|
// Fetch space details
|
||||||
|
const spaceDetails = await this.getSpaceByUuid(spaceUuid);
|
||||||
|
|
||||||
|
// Fetch device UUIDs for the space
|
||||||
|
const deviceUUIDs =
|
||||||
|
await this.userSpaceService.getDeviceUUIDsForSpace(spaceUuid);
|
||||||
|
|
||||||
|
// Grant permissions to the user for all devices in the space
|
||||||
|
await this.userSpaceService.addUserPermissionsToDevices(
|
||||||
|
userData.user.uuid,
|
||||||
|
deviceUUIDs,
|
||||||
|
);
|
||||||
|
|
||||||
|
// Associate the user with the new space
|
||||||
|
await this.spaceUserService.associateUserToSpace({
|
||||||
|
communityUuid: spaceDetails.communityUuid,
|
||||||
|
spaceUuid: spaceUuid,
|
||||||
|
userUuid: userData.user.uuid,
|
||||||
|
projectUuid,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Failed to process space ${spaceUuid}:`, error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.all(associatePromises);
|
||||||
|
}
|
||||||
|
|
||||||
|
async getSpaceByUuid(spaceUuid: string) {
|
||||||
|
try {
|
||||||
|
const space = await this.spaceRepository.findOne({
|
||||||
|
where: {
|
||||||
|
uuid: spaceUuid,
|
||||||
|
},
|
||||||
|
relations: ['community'],
|
||||||
|
});
|
||||||
|
if (!space) {
|
||||||
|
throw new BadRequestException(`Invalid space UUID ${spaceUuid}`);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
uuid: space.uuid,
|
||||||
|
createdAt: space.createdAt,
|
||||||
|
updatedAt: space.updatedAt,
|
||||||
|
name: space.spaceName,
|
||||||
|
spaceTuyaUuid: space.community.externalId,
|
||||||
|
communityUuid: space.community.uuid,
|
||||||
|
};
|
||||||
|
} catch (err) {
|
||||||
|
if (err instanceof BadRequestException) {
|
||||||
|
throw err; // Re-throw BadRequestException
|
||||||
|
} else {
|
||||||
|
throw new HttpException('Space not found', HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
async disableUserInvitation(
|
async disableUserInvitation(
|
||||||
dto: DisableUserInvitationDto,
|
dto: DisableUserInvitationDto,
|
||||||
invitedUserUuid: string,
|
invitedUserUuid: string,
|
||||||
@ -349,6 +685,74 @@ export class InviteUserService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async updateUserStatus(
|
||||||
|
invitedUserUuid: string,
|
||||||
|
projectUuid: string,
|
||||||
|
isEnabled: boolean,
|
||||||
|
) {
|
||||||
|
await this.inviteUserRepository.update(
|
||||||
|
{ uuid: invitedUserUuid, project: { uuid: projectUuid } },
|
||||||
|
{ isEnabled },
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
private async disassociateUserFromSpaces(user: any, projectUuid: string) {
|
||||||
|
const disassociatePromises = user.userSpaces.map((userSpace) =>
|
||||||
|
this.spaceUserService.disassociateUserFromSpace({
|
||||||
|
communityUuid: userSpace.space.community.uuid,
|
||||||
|
spaceUuid: userSpace.space.uuid,
|
||||||
|
userUuid: user.uuid,
|
||||||
|
projectUuid,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
const results = await Promise.allSettled(disassociatePromises);
|
||||||
|
|
||||||
|
results.forEach((result, index) => {
|
||||||
|
if (result.status === 'rejected') {
|
||||||
|
console.error(
|
||||||
|
`Failed to disassociate user from space ${user.userSpaces[index].space.uuid}:`,
|
||||||
|
result.reason,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private async associateUserToSpaces(
|
||||||
|
user: any,
|
||||||
|
userData: any,
|
||||||
|
projectUuid: string,
|
||||||
|
invitedUserUuid: string,
|
||||||
|
disable: boolean,
|
||||||
|
) {
|
||||||
|
const spaceUuids = userData.spaces.map((space) => space.space.uuid);
|
||||||
|
|
||||||
|
const associatePromises = spaceUuids.map(async (spaceUuid) => {
|
||||||
|
try {
|
||||||
|
const spaceDetails = await this.getSpaceByUuid(spaceUuid);
|
||||||
|
|
||||||
|
const deviceUUIDs =
|
||||||
|
await this.userSpaceService.getDeviceUUIDsForSpace(spaceUuid);
|
||||||
|
await this.userSpaceService.addUserPermissionsToDevices(
|
||||||
|
user.uuid,
|
||||||
|
deviceUUIDs,
|
||||||
|
);
|
||||||
|
|
||||||
|
await this.spaceUserService.associateUserToSpace({
|
||||||
|
communityUuid: spaceDetails.communityUuid,
|
||||||
|
spaceUuid,
|
||||||
|
userUuid: user.uuid,
|
||||||
|
projectUuid,
|
||||||
|
});
|
||||||
|
|
||||||
|
await this.updateUserStatus(invitedUserUuid, projectUuid, disable);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(`Failed to associate user to space ${spaceUuid}:`, error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await Promise.allSettled(associatePromises);
|
||||||
|
}
|
||||||
|
|
||||||
async deleteUserInvitation(
|
async deleteUserInvitation(
|
||||||
invitedUserUuid: string,
|
invitedUserUuid: string,
|
||||||
): Promise<BaseResponseDto> {
|
): Promise<BaseResponseDto> {
|
||||||
@ -419,486 +823,4 @@ export class InviteUserService {
|
|||||||
await queryRunner.release();
|
await queryRunner.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async activationCode(dto: ActivateCodeDto): Promise<BaseResponseDto> {
|
|
||||||
const { activationCode, userUuid } = dto;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const user = await this.getUser(userUuid);
|
|
||||||
|
|
||||||
const invitedUser = await this.inviteUserRepository.findOne({
|
|
||||||
where: {
|
|
||||||
email: user.email,
|
|
||||||
status: UserStatusEnum.INVITED,
|
|
||||||
isActive: true,
|
|
||||||
},
|
|
||||||
relations: ['project', 'spaces.space.community', 'roleType'],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (invitedUser) {
|
|
||||||
if (invitedUser.invitationCode !== activationCode) {
|
|
||||||
throw new HttpException(
|
|
||||||
'Invalid activation code',
|
|
||||||
HttpStatus.BAD_REQUEST,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Handle invited user with valid activation code
|
|
||||||
await this.handleInvitedUser(user, invitedUser);
|
|
||||||
} else {
|
|
||||||
// Handle case for non-invited user
|
|
||||||
await this.handleNonInvitedUser(activationCode, userUuid);
|
|
||||||
}
|
|
||||||
return new SuccessResponseDto({
|
|
||||||
statusCode: HttpStatus.OK,
|
|
||||||
success: true,
|
|
||||||
message: 'The code has been successfully activated',
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error activating the code:', error);
|
|
||||||
throw new HttpException(
|
|
||||||
error.message ||
|
|
||||||
'An unexpected error occurred while activating the code',
|
|
||||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async checkEmailAndProject(dto: CheckEmailDto): Promise<BaseResponseDto> {
|
|
||||||
const { email } = dto;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const user = await this.userRepository.findOne({
|
|
||||||
where: { email },
|
|
||||||
relations: ['project'],
|
|
||||||
});
|
|
||||||
this.validateUserOrInvite(user, 'User');
|
|
||||||
const invitedUser = await this.inviteUserRepository.findOne({
|
|
||||||
where: { email },
|
|
||||||
relations: ['project'],
|
|
||||||
});
|
|
||||||
this.validateUserOrInvite(invitedUser, 'Invited User');
|
|
||||||
|
|
||||||
return new SuccessResponseDto({
|
|
||||||
statusCode: HttpStatus.OK,
|
|
||||||
success: true,
|
|
||||||
message: 'Valid email',
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error checking email and project:', error);
|
|
||||||
throw new HttpException(
|
|
||||||
error.message ||
|
|
||||||
'An unexpected error occurred while checking the email',
|
|
||||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getSpaceByUuid(spaceUuid: string) {
|
|
||||||
try {
|
|
||||||
const space = await this.spaceRepository.findOne({
|
|
||||||
where: {
|
|
||||||
uuid: spaceUuid,
|
|
||||||
},
|
|
||||||
relations: ['community'],
|
|
||||||
});
|
|
||||||
if (!space) {
|
|
||||||
throw new BadRequestException(`Invalid space UUID ${spaceUuid}`);
|
|
||||||
}
|
|
||||||
return {
|
|
||||||
uuid: space.uuid,
|
|
||||||
createdAt: space.createdAt,
|
|
||||||
updatedAt: space.updatedAt,
|
|
||||||
name: space.spaceName,
|
|
||||||
spaceTuyaUuid: space.community.externalId,
|
|
||||||
communityUuid: space.community.uuid,
|
|
||||||
};
|
|
||||||
} catch (err) {
|
|
||||||
if (err instanceof BadRequestException) {
|
|
||||||
throw err; // Re-throw BadRequestException
|
|
||||||
} else {
|
|
||||||
throw new HttpException('Space not found', HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async validateSpaces(
|
|
||||||
spaceUuids: string[],
|
|
||||||
entityManager: EntityManager,
|
|
||||||
): Promise<SpaceEntity[]> {
|
|
||||||
const spaceRepo = entityManager.getRepository(SpaceEntity);
|
|
||||||
|
|
||||||
const validSpaces = await spaceRepo.find({
|
|
||||||
where: { uuid: In(spaceUuids) },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (validSpaces.length !== spaceUuids.length) {
|
|
||||||
const validSpaceUuids = validSpaces.map((space) => space.uuid);
|
|
||||||
const invalidSpaceUuids = spaceUuids.filter(
|
|
||||||
(uuid) => !validSpaceUuids.includes(uuid),
|
|
||||||
);
|
|
||||||
throw new HttpException(
|
|
||||||
`Invalid space UUIDs: ${invalidSpaceUuids.join(', ')}`,
|
|
||||||
HttpStatus.BAD_REQUEST,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return validSpaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async checkRole(
|
|
||||||
roleUuid: string,
|
|
||||||
queryRunner: QueryRunner,
|
|
||||||
): Promise<BaseResponseDto> {
|
|
||||||
try {
|
|
||||||
const role = await queryRunner.manager.findOne(RoleTypeEntity, {
|
|
||||||
where: { uuid: roleUuid },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!role) {
|
|
||||||
throw new HttpException('Role not found', HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new SuccessResponseDto({
|
|
||||||
statusCode: HttpStatus.OK,
|
|
||||||
success: true,
|
|
||||||
message: 'Valid role',
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error checking role:', error);
|
|
||||||
throw new HttpException(
|
|
||||||
error.message || 'An unexpected error occurred while checking the role',
|
|
||||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async checkProject(
|
|
||||||
projectUuid: string,
|
|
||||||
queryRunner: QueryRunner,
|
|
||||||
): Promise<BaseResponseDto> {
|
|
||||||
try {
|
|
||||||
const project = await queryRunner.manager.findOne(ProjectEntity, {
|
|
||||||
where: { uuid: projectUuid },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!project) {
|
|
||||||
throw new HttpException('Project not found', HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new SuccessResponseDto({
|
|
||||||
statusCode: HttpStatus.OK,
|
|
||||||
success: true,
|
|
||||||
message: 'Valid project',
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error checking project:', error);
|
|
||||||
throw new HttpException(
|
|
||||||
error.message ||
|
|
||||||
'An unexpected error occurred while checking the project',
|
|
||||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private validateUserOrInvite(user: any, userType: string): void {
|
|
||||||
if (user) {
|
|
||||||
if (!user.isActive) {
|
|
||||||
throw new HttpException(
|
|
||||||
`${userType} is deleted`,
|
|
||||||
HttpStatus.BAD_REQUEST,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (user.project) {
|
|
||||||
throw new HttpException(
|
|
||||||
`${userType} already has a project`,
|
|
||||||
HttpStatus.BAD_REQUEST,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getUser(userUuid: string): Promise<UserEntity> {
|
|
||||||
const user = await this.userRepository.findOne({
|
|
||||||
where: { uuid: userUuid, isActive: true, isUserVerified: true },
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
throw new HttpException('User not found', HttpStatus.NOT_FOUND);
|
|
||||||
}
|
|
||||||
return user;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async handleNonInvitedUser(
|
|
||||||
activationCode: string,
|
|
||||||
userUuid: string,
|
|
||||||
): Promise<void> {
|
|
||||||
await this.userSpaceService.verifyCodeAndAddUserSpace(
|
|
||||||
{ inviteCode: activationCode },
|
|
||||||
userUuid,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async handleInvitedUser(
|
|
||||||
user: UserEntity,
|
|
||||||
invitedUser: InviteUserEntity,
|
|
||||||
): Promise<void> {
|
|
||||||
for (const invitedSpace of invitedUser.spaces) {
|
|
||||||
try {
|
|
||||||
const deviceUUIDs = await this.userSpaceService.getDeviceUUIDsForSpace(
|
|
||||||
invitedSpace.space.uuid,
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.userSpaceService.addUserPermissionsToDevices(
|
|
||||||
user.uuid,
|
|
||||||
deviceUUIDs,
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.spaceUserService.associateUserToSpace({
|
|
||||||
communityUuid: invitedSpace.space.community.uuid,
|
|
||||||
spaceUuid: invitedSpace.space.uuid,
|
|
||||||
userUuid: user.uuid,
|
|
||||||
projectUuid: invitedUser.project.uuid,
|
|
||||||
});
|
|
||||||
} catch (spaceError) {
|
|
||||||
console.error(
|
|
||||||
`Error processing space ${invitedSpace.space.uuid}:`,
|
|
||||||
spaceError,
|
|
||||||
);
|
|
||||||
continue; // Skip to the next space
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update invited user and associated user data
|
|
||||||
await this.inviteUserRepository.update(
|
|
||||||
{ uuid: invitedUser.uuid },
|
|
||||||
{ status: UserStatusEnum.ACTIVE, user: { uuid: user.uuid } },
|
|
||||||
);
|
|
||||||
await this.userRepository.update(
|
|
||||||
{ uuid: user.uuid },
|
|
||||||
{
|
|
||||||
project: { uuid: invitedUser.project.uuid },
|
|
||||||
roleType: { uuid: invitedUser.roleType.uuid },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async getRoleTypeByUuid(roleUuid: string) {
|
|
||||||
const role = await this.roleTypeRepository.findOne({
|
|
||||||
where: { uuid: roleUuid },
|
|
||||||
});
|
|
||||||
|
|
||||||
return role.type;
|
|
||||||
}
|
|
||||||
|
|
||||||
private async updateWhenUserIsInvite(
|
|
||||||
queryRunner: QueryRunner,
|
|
||||||
dto: UpdateUserInvitationDto,
|
|
||||||
invitedUserUuid: string,
|
|
||||||
): Promise<void> {
|
|
||||||
const {
|
|
||||||
firstName,
|
|
||||||
lastName,
|
|
||||||
jobTitle,
|
|
||||||
companyName,
|
|
||||||
phoneNumber,
|
|
||||||
roleUuid,
|
|
||||||
spaceUuids,
|
|
||||||
} = dto;
|
|
||||||
|
|
||||||
// Update user invitation details
|
|
||||||
await queryRunner.manager.update(
|
|
||||||
this.inviteUserRepository.target,
|
|
||||||
{ uuid: invitedUserUuid },
|
|
||||||
{
|
|
||||||
firstName,
|
|
||||||
lastName,
|
|
||||||
jobTitle,
|
|
||||||
companyName,
|
|
||||||
phoneNumber,
|
|
||||||
roleType: { uuid: roleUuid },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Remove old space associations
|
|
||||||
await queryRunner.manager.delete(this.inviteUserSpaceRepository.target, {
|
|
||||||
inviteUser: { uuid: invitedUserUuid },
|
|
||||||
});
|
|
||||||
|
|
||||||
// Save new space associations
|
|
||||||
const spaceData = spaceUuids.map((spaceUuid) => ({
|
|
||||||
inviteUser: { uuid: invitedUserUuid },
|
|
||||||
space: { uuid: spaceUuid },
|
|
||||||
}));
|
|
||||||
await queryRunner.manager.save(
|
|
||||||
this.inviteUserSpaceRepository.target,
|
|
||||||
spaceData,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
private async updateWhenUserIsActive(
|
|
||||||
queryRunner: QueryRunner,
|
|
||||||
dto: UpdateUserInvitationDto,
|
|
||||||
invitedUserUuid: string,
|
|
||||||
): Promise<void> {
|
|
||||||
const {
|
|
||||||
firstName,
|
|
||||||
lastName,
|
|
||||||
jobTitle,
|
|
||||||
companyName,
|
|
||||||
phoneNumber,
|
|
||||||
roleUuid,
|
|
||||||
spaceUuids,
|
|
||||||
projectUuid,
|
|
||||||
} = dto;
|
|
||||||
|
|
||||||
const userData = await this.inviteUserRepository.findOne({
|
|
||||||
where: { uuid: invitedUserUuid },
|
|
||||||
relations: ['user.userSpaces.space', 'user.userSpaces.space.community'],
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!userData) {
|
|
||||||
throw new HttpException(
|
|
||||||
`User with invitedUserUuid ${invitedUserUuid} not found`,
|
|
||||||
HttpStatus.NOT_FOUND,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update user details
|
|
||||||
await queryRunner.manager.update(
|
|
||||||
this.inviteUserRepository.target,
|
|
||||||
{ uuid: invitedUserUuid },
|
|
||||||
{
|
|
||||||
firstName,
|
|
||||||
lastName,
|
|
||||||
jobTitle,
|
|
||||||
companyName,
|
|
||||||
phoneNumber,
|
|
||||||
roleType: { uuid: roleUuid },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
await this.userRepository.update(
|
|
||||||
{ uuid: userData.user.uuid },
|
|
||||||
{
|
|
||||||
roleType: { uuid: roleUuid },
|
|
||||||
},
|
|
||||||
);
|
|
||||||
// Disassociate the user from all current spaces
|
|
||||||
const disassociatePromises = userData.user.userSpaces.map((userSpace) =>
|
|
||||||
this.spaceUserService
|
|
||||||
.disassociateUserFromSpace({
|
|
||||||
communityUuid: userSpace.space.community.uuid,
|
|
||||||
spaceUuid: userSpace.space.uuid,
|
|
||||||
userUuid: userData.user.uuid,
|
|
||||||
projectUuid,
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.error(
|
|
||||||
`Failed to disassociate user from space ${userSpace.space.uuid}:`,
|
|
||||||
error,
|
|
||||||
);
|
|
||||||
throw error;
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
await Promise.allSettled(disassociatePromises);
|
|
||||||
|
|
||||||
// Process new spaces
|
|
||||||
const associatePromises = spaceUuids.map(async (spaceUuid) => {
|
|
||||||
try {
|
|
||||||
// Fetch space details
|
|
||||||
const spaceDetails = await this.getSpaceByUuid(spaceUuid);
|
|
||||||
|
|
||||||
// Fetch device UUIDs for the space
|
|
||||||
const deviceUUIDs =
|
|
||||||
await this.userSpaceService.getDeviceUUIDsForSpace(spaceUuid);
|
|
||||||
|
|
||||||
// Grant permissions to the user for all devices in the space
|
|
||||||
await this.userSpaceService.addUserPermissionsToDevices(
|
|
||||||
userData.user.uuid,
|
|
||||||
deviceUUIDs,
|
|
||||||
);
|
|
||||||
|
|
||||||
// Associate the user with the new space
|
|
||||||
await this.spaceUserService.associateUserToSpace({
|
|
||||||
communityUuid: spaceDetails.communityUuid,
|
|
||||||
spaceUuid: spaceUuid,
|
|
||||||
userUuid: userData.user.uuid,
|
|
||||||
projectUuid,
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Failed to process space ${spaceUuid}:`, error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.all(associatePromises);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async updateUserStatus(
|
|
||||||
invitedUserUuid: string,
|
|
||||||
projectUuid: string,
|
|
||||||
isEnabled: boolean,
|
|
||||||
) {
|
|
||||||
await this.inviteUserRepository.update(
|
|
||||||
{ uuid: invitedUserUuid, project: { uuid: projectUuid } },
|
|
||||||
{ isEnabled },
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async disassociateUserFromSpaces(user: any, projectUuid: string) {
|
|
||||||
const disassociatePromises = user.userSpaces.map((userSpace) =>
|
|
||||||
this.spaceUserService.disassociateUserFromSpace({
|
|
||||||
communityUuid: userSpace.space.community.uuid,
|
|
||||||
spaceUuid: userSpace.space.uuid,
|
|
||||||
userUuid: user.uuid,
|
|
||||||
projectUuid,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
|
|
||||||
const results = await Promise.allSettled(disassociatePromises);
|
|
||||||
|
|
||||||
results.forEach((result, index) => {
|
|
||||||
if (result.status === 'rejected') {
|
|
||||||
console.error(
|
|
||||||
`Failed to disassociate user from space ${user.userSpaces[index].space.uuid}:`,
|
|
||||||
result.reason,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
private async associateUserToSpaces(
|
|
||||||
user: any,
|
|
||||||
userData: any,
|
|
||||||
projectUuid: string,
|
|
||||||
invitedUserUuid: string,
|
|
||||||
disable: boolean,
|
|
||||||
) {
|
|
||||||
const spaceUuids = userData.spaces.map((space) => space.space.uuid);
|
|
||||||
|
|
||||||
const associatePromises = spaceUuids.map(async (spaceUuid) => {
|
|
||||||
try {
|
|
||||||
const spaceDetails = await this.getSpaceByUuid(spaceUuid);
|
|
||||||
|
|
||||||
const deviceUUIDs =
|
|
||||||
await this.userSpaceService.getDeviceUUIDsForSpace(spaceUuid);
|
|
||||||
await this.userSpaceService.addUserPermissionsToDevices(
|
|
||||||
user.uuid,
|
|
||||||
deviceUUIDs,
|
|
||||||
);
|
|
||||||
|
|
||||||
await this.spaceUserService.associateUserToSpace({
|
|
||||||
communityUuid: spaceDetails.communityUuid,
|
|
||||||
spaceUuid,
|
|
||||||
userUuid: user.uuid,
|
|
||||||
projectUuid,
|
|
||||||
});
|
|
||||||
|
|
||||||
await this.updateUserStatus(invitedUserUuid, projectUuid, disable);
|
|
||||||
} catch (error) {
|
|
||||||
console.error(`Failed to associate user to space ${spaceUuid}:`, error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
await Promise.allSettled(associatePromises);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,24 +1,25 @@
|
|||||||
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,
|
||||||
@ -26,6 +27,7 @@ import { PowerClampService } from '../services/power-clamp.service';
|
|||||||
})
|
})
|
||||||
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')
|
||||||
|
@ -22,6 +22,7 @@ import {
|
|||||||
} from '@app/common/modules/scene/repositories';
|
} from '@app/common/modules/scene/repositories';
|
||||||
import {
|
import {
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
|
SpaceLinkRepository,
|
||||||
SpaceProductAllocationRepository,
|
SpaceProductAllocationRepository,
|
||||||
SpaceRepository,
|
SpaceRepository,
|
||||||
} from '@app/common/modules/space';
|
} from '@app/common/modules/space';
|
||||||
@ -95,6 +96,7 @@ import { AqiSpaceDailyPollutantStatsRepository } from '@app/common/modules/aqi/r
|
|||||||
SpaceModelService,
|
SpaceModelService,
|
||||||
SpaceProductAllocationService,
|
SpaceProductAllocationService,
|
||||||
SqlLoaderService,
|
SqlLoaderService,
|
||||||
|
SpaceLinkRepository,
|
||||||
SubspaceRepository,
|
SubspaceRepository,
|
||||||
SubspaceDeviceService,
|
SubspaceDeviceService,
|
||||||
SubspaceProductAllocationService,
|
SubspaceProductAllocationService,
|
||||||
|
@ -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 {
|
||||||
|
@ -23,6 +23,7 @@ import {
|
|||||||
} from '@app/common/modules/scene/repositories';
|
} from '@app/common/modules/scene/repositories';
|
||||||
import {
|
import {
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
|
SpaceLinkRepository,
|
||||||
SpaceProductAllocationRepository,
|
SpaceProductAllocationRepository,
|
||||||
SpaceRepository,
|
SpaceRepository,
|
||||||
} from '@app/common/modules/space';
|
} from '@app/common/modules/space';
|
||||||
@ -93,6 +94,7 @@ const CommandHandlers = [CreateOrphanSpaceHandler];
|
|||||||
SpaceModelService,
|
SpaceModelService,
|
||||||
DeviceService,
|
DeviceService,
|
||||||
SpaceProductAllocationService,
|
SpaceProductAllocationService,
|
||||||
|
SpaceLinkRepository,
|
||||||
SubspaceRepository,
|
SubspaceRepository,
|
||||||
SubspaceDeviceService,
|
SubspaceDeviceService,
|
||||||
SubspaceProductAllocationService,
|
SubspaceProductAllocationService,
|
||||||
|
@ -33,7 +33,6 @@ export class ProjectUserService {
|
|||||||
'status',
|
'status',
|
||||||
'phoneNumber',
|
'phoneNumber',
|
||||||
'jobTitle',
|
'jobTitle',
|
||||||
'companyName',
|
|
||||||
'invitedBy',
|
'invitedBy',
|
||||||
'isEnabled',
|
'isEnabled',
|
||||||
],
|
],
|
||||||
@ -92,7 +91,6 @@ export class ProjectUserService {
|
|||||||
'status',
|
'status',
|
||||||
'phoneNumber',
|
'phoneNumber',
|
||||||
'jobTitle',
|
'jobTitle',
|
||||||
'companyName',
|
|
||||||
'invitedBy',
|
'invitedBy',
|
||||||
'isEnabled',
|
'isEnabled',
|
||||||
],
|
],
|
||||||
|
@ -96,26 +96,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,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
||||||
);
|
);
|
||||||
@ -123,7 +103,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(
|
||||||
@ -146,14 +125,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,
|
||||||
@ -184,26 +159,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,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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,
|
||||||
@ -212,7 +167,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(
|
||||||
@ -238,7 +192,6 @@ 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);
|
||||||
@ -257,10 +210,7 @@ export class ScheduleService {
|
|||||||
...addScheduleDto.function,
|
...addScheduleDto.function,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
category:
|
category: `category_${addScheduleDto.category}`,
|
||||||
deviceType == ProductType.CUR_2
|
|
||||||
? addScheduleDto.category
|
|
||||||
: `category_${addScheduleDto.category}`,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -276,12 +226,9 @@ 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 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,
|
||||||
@ -301,7 +248,6 @@ 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);
|
||||||
@ -322,10 +268,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}`,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ import {
|
|||||||
} from '@app/common/modules/scene/repositories';
|
} from '@app/common/modules/scene/repositories';
|
||||||
import {
|
import {
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
|
SpaceLinkRepository,
|
||||||
SpaceProductAllocationRepository,
|
SpaceProductAllocationRepository,
|
||||||
SpaceRepository,
|
SpaceRepository,
|
||||||
} from '@app/common/modules/space';
|
} from '@app/common/modules/space';
|
||||||
@ -92,6 +93,7 @@ const CommandHandlers = [
|
|||||||
DeviceRepository,
|
DeviceRepository,
|
||||||
TuyaService,
|
TuyaService,
|
||||||
CommunityRepository,
|
CommunityRepository,
|
||||||
|
SpaceLinkRepository,
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
NewTagService,
|
NewTagService,
|
||||||
DeviceService,
|
DeviceService,
|
||||||
|
@ -1,26 +1,23 @@
|
|||||||
|
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
||||||
|
import { SpaceService } from '../services';
|
||||||
import { ControllerRoute } from '@app/common/constants/controller-route';
|
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
|
||||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
|
||||||
import {
|
import {
|
||||||
Body,
|
Body,
|
||||||
Controller,
|
Controller,
|
||||||
Delete,
|
Delete,
|
||||||
Get,
|
Get,
|
||||||
Param,
|
Param,
|
||||||
ParseUUIDPipe,
|
|
||||||
Post,
|
Post,
|
||||||
Put,
|
Put,
|
||||||
Query,
|
Query,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
||||||
import { Permissions } from 'src/decorators/permissions.decorator';
|
|
||||||
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
|
||||||
import { AddSpaceDto, CommunitySpaceParam, UpdateSpaceDto } from '../dtos';
|
import { AddSpaceDto, CommunitySpaceParam, UpdateSpaceDto } from '../dtos';
|
||||||
import { GetSpaceDto } from '../dtos/get.space.dto';
|
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||||
import { GetSpaceParam } from '../dtos/get.space.param';
|
import { GetSpaceParam } from '../dtos/get.space.param';
|
||||||
import { OrderSpacesDto } from '../dtos/order.spaces.dto';
|
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
||||||
import { SpaceService } from '../services';
|
import { Permissions } from 'src/decorators/permissions.decorator';
|
||||||
|
import { GetSpaceDto } from '../dtos/get.space.dto';
|
||||||
|
|
||||||
@ApiTags('Space Module')
|
@ApiTags('Space Module')
|
||||||
@Controller({
|
@Controller({
|
||||||
@ -68,30 +65,6 @@ export class SpaceController {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
|
||||||
@UseGuards(PermissionsGuard)
|
|
||||||
@Permissions('SPACE_UPDATE')
|
|
||||||
@ApiOperation({
|
|
||||||
summary:
|
|
||||||
ControllerRoute.SPACE.ACTIONS
|
|
||||||
.UPDATE_CHILDREN_SPACES_ORDER_OF_A_SPACE_SUMMARY,
|
|
||||||
description:
|
|
||||||
ControllerRoute.SPACE.ACTIONS
|
|
||||||
.UPDATE_CHILDREN_SPACES_ORDER_OF_A_SPACE_DESCRIPTION,
|
|
||||||
})
|
|
||||||
@Post(':parentSpaceUuid/spaces/order')
|
|
||||||
async updateSpacesOrder(
|
|
||||||
@Body() orderSpacesDto: OrderSpacesDto,
|
|
||||||
@Param() communitySpaceParam: CommunitySpaceParam,
|
|
||||||
@Param('parentSpaceUuid', ParseUUIDPipe) parentSpaceUuid: string,
|
|
||||||
) {
|
|
||||||
await this.spaceService.updateSpacesOrder(parentSpaceUuid, orderSpacesDto);
|
|
||||||
return new SuccessResponseDto({
|
|
||||||
statusCode: 200,
|
|
||||||
message: 'Spaces order updated successfully',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(PermissionsGuard)
|
@UseGuards(PermissionsGuard)
|
||||||
@Permissions('SPACE_DELETE')
|
@Permissions('SPACE_DELETE')
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
import { ApiProperty } from '@nestjs/swagger';
|
|
||||||
import { ArrayUnique, IsNotEmpty, IsUUID } from 'class-validator';
|
|
||||||
|
|
||||||
export class OrderSpacesDto {
|
|
||||||
@ApiProperty({
|
|
||||||
description: 'List of children spaces associated with the space',
|
|
||||||
type: [String],
|
|
||||||
})
|
|
||||||
@IsNotEmpty()
|
|
||||||
@ArrayUnique()
|
|
||||||
@IsUUID('4', { each: true, message: 'Invalid space UUID provided' })
|
|
||||||
spacesUuids: string[];
|
|
||||||
}
|
|
@ -2,7 +2,6 @@ import { ORPHAN_SPACE_NAME } from '@app/common/constants/orphan-constant';
|
|||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
import { Type } from 'class-transformer';
|
import { Type } from 'class-transformer';
|
||||||
import {
|
import {
|
||||||
ArrayUnique,
|
|
||||||
IsArray,
|
IsArray,
|
||||||
IsNumber,
|
IsNumber,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
@ -50,21 +49,6 @@ export class UpdateSpaceDto {
|
|||||||
description: 'List of subspace modifications',
|
description: 'List of subspace modifications',
|
||||||
type: [UpdateSubspaceDto],
|
type: [UpdateSubspaceDto],
|
||||||
})
|
})
|
||||||
@ArrayUnique((subspace) => subspace.subspaceName ?? subspace.uuid, {
|
|
||||||
message(validationArguments) {
|
|
||||||
const subspaces = validationArguments.value;
|
|
||||||
const nameCounts = subspaces.reduce((acc, curr) => {
|
|
||||||
acc[curr.subspaceName ?? curr.uuid] =
|
|
||||||
(acc[curr.subspaceName ?? curr.uuid] || 0) + 1;
|
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
// Find duplicates
|
|
||||||
const duplicates = Object.keys(nameCounts).filter(
|
|
||||||
(name) => nameCounts[name] > 1,
|
|
||||||
);
|
|
||||||
return `Duplicate subspace names found: ${duplicates.join(', ')}`;
|
|
||||||
},
|
|
||||||
})
|
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ValidateNested({ each: true })
|
@ValidateNested({ each: true })
|
||||||
|
@ -2,5 +2,6 @@ export * from './space.service';
|
|||||||
export * from './space-user.service';
|
export * from './space-user.service';
|
||||||
export * from './space-device.service';
|
export * from './space-device.service';
|
||||||
export * from './subspace';
|
export * from './subspace';
|
||||||
|
export * from './space-link';
|
||||||
export * from './space-scene.service';
|
export * from './space-scene.service';
|
||||||
export * from './space-validation.service';
|
export * from './space-validation.service';
|
||||||
|
1
src/space/services/space-link/index.ts
Normal file
1
src/space/services/space-link/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './space-link.service';
|
6
src/space/services/space-link/space-link.service.ts
Normal file
6
src/space/services/space-link/space-link.service.ts
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
// todo: find out why we need to import this
|
||||||
|
// in community module in order for the whole system to work
|
||||||
|
@Injectable()
|
||||||
|
export class SpaceLinkService {}
|
@ -33,7 +33,6 @@ import {
|
|||||||
} from '../dtos';
|
} from '../dtos';
|
||||||
import { CreateProductAllocationDto } from '../dtos/create-product-allocation.dto';
|
import { CreateProductAllocationDto } from '../dtos/create-product-allocation.dto';
|
||||||
import { GetSpaceDto } from '../dtos/get.space.dto';
|
import { GetSpaceDto } from '../dtos/get.space.dto';
|
||||||
import { OrderSpacesDto } from '../dtos/order.spaces.dto';
|
|
||||||
import { SpaceWithParentsDto } from '../dtos/space.parents.dto';
|
import { SpaceWithParentsDto } from '../dtos/space.parents.dto';
|
||||||
import { SpaceProductAllocationService } from './space-product-allocation.service';
|
import { SpaceProductAllocationService } from './space-product-allocation.service';
|
||||||
import { ValidationService } from './space-validation.service';
|
import { ValidationService } from './space-validation.service';
|
||||||
@ -356,54 +355,6 @@ export class SpaceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async updateSpacesOrder(
|
|
||||||
parentSpaceUuid: string,
|
|
||||||
{ spacesUuids }: OrderSpacesDto,
|
|
||||||
) {
|
|
||||||
const parentSpace = await this.spaceRepository.findOne({
|
|
||||||
where: { uuid: parentSpaceUuid, disabled: false },
|
|
||||||
relations: ['children'],
|
|
||||||
});
|
|
||||||
if (!parentSpace) {
|
|
||||||
throw new HttpException(
|
|
||||||
`Parent space with ID ${parentSpaceUuid} not found`,
|
|
||||||
HttpStatus.NOT_FOUND,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
// ensure that all sent spaces belong to the parent space
|
|
||||||
const missingSpaces = spacesUuids.filter(
|
|
||||||
(uuid) => !parentSpace.children.some((child) => child.uuid === uuid),
|
|
||||||
);
|
|
||||||
if (missingSpaces.length > 0) {
|
|
||||||
throw new HttpException(
|
|
||||||
`Some spaces with IDs ${missingSpaces.join(
|
|
||||||
', ',
|
|
||||||
)} do not belong to the parent space with ID ${parentSpaceUuid}`,
|
|
||||||
HttpStatus.BAD_REQUEST,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
await this.spaceRepository.update(
|
|
||||||
{ uuid: In(spacesUuids), parent: { uuid: parentSpaceUuid } },
|
|
||||||
{
|
|
||||||
order: () =>
|
|
||||||
'CASE ' +
|
|
||||||
spacesUuids
|
|
||||||
.map((s, index) => `WHEN uuid = '${s}' THEN ${index + 1}`)
|
|
||||||
.join(' ') +
|
|
||||||
' END',
|
|
||||||
},
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error updating spaces order:', error);
|
|
||||||
throw new HttpException(
|
|
||||||
'An error occurred while updating spaces order',
|
|
||||||
HttpStatus.INTERNAL_SERVER_ERROR,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async delete(params: GetSpaceParam): Promise<BaseResponseDto> {
|
async delete(params: GetSpaceParam): Promise<BaseResponseDto> {
|
||||||
const queryRunner = this.dataSource.createQueryRunner();
|
const queryRunner = this.dataSource.createQueryRunner();
|
||||||
await queryRunner.connect();
|
await queryRunner.connect();
|
||||||
@ -475,7 +426,7 @@ export class SpaceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async disableSpace(space: SpaceEntity, orphanSpace: SpaceEntity) {
|
async disableSpace(space: SpaceEntity, orphanSpace: SpaceEntity) {
|
||||||
await this.commandBus.execute(
|
await this.commandBus.execute(
|
||||||
new DisableSpaceCommand({ spaceUuid: space.uuid, orphanSpace }),
|
new DisableSpaceCommand({ spaceUuid: space.uuid, orphanSpace }),
|
||||||
);
|
);
|
||||||
@ -758,19 +709,8 @@ export class SpaceService {
|
|||||||
rootSpaces.push(map.get(space.uuid)!); // Push only root spaces
|
rootSpaces.push(map.get(space.uuid)!); // Push only root spaces
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
rootSpaces.forEach(this.sortSpaceChildren.bind(this));
|
|
||||||
return rootSpaces;
|
|
||||||
}
|
|
||||||
|
|
||||||
private sortSpaceChildren(space: SpaceEntity) {
|
return rootSpaces;
|
||||||
if (space.children && space.children.length > 0) {
|
|
||||||
space.children.sort((a, b) => {
|
|
||||||
const aOrder = a.order ?? Infinity;
|
|
||||||
const bOrder = b.order ?? Infinity;
|
|
||||||
return aOrder - bOrder;
|
|
||||||
});
|
|
||||||
space.children.forEach(this.sortSpaceChildren.bind(this)); // Recursively sort children of children
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private validateSpaceCreationCriteria({
|
private validateSpaceCreationCriteria({
|
||||||
|
@ -23,7 +23,7 @@ export class SubspaceProductAllocationService {
|
|||||||
// spaceAllocationsToExclude?: SpaceProductAllocationEntity[],
|
// spaceAllocationsToExclude?: SpaceProductAllocationEntity[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
try {
|
try {
|
||||||
if (!allocationsData?.length) return;
|
if (!allocationsData.length) return;
|
||||||
|
|
||||||
const allocations: SubspaceProductAllocationEntity[] = [];
|
const allocations: SubspaceProductAllocationEntity[] = [];
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ export class SubspaceProductAllocationService {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Create the product-tag mapping based on the processed tags
|
// Create the product-tag mapping based on the processed tags
|
||||||
const productTagMapping = subspace.productAllocations?.map(
|
const productTagMapping = subspace.productAllocations.map(
|
||||||
({ tagUuid, tagName, productUuid }) => {
|
({ tagUuid, tagName, productUuid }) => {
|
||||||
const inputTag = tagUuid
|
const inputTag = tagUuid
|
||||||
? createdTagsByUUID.get(tagUuid)
|
? createdTagsByUUID.get(tagUuid)
|
||||||
|
@ -39,7 +39,7 @@ export class SubSpaceService {
|
|||||||
private readonly subspaceProductAllocationService: SubspaceProductAllocationService,
|
private readonly subspaceProductAllocationService: SubspaceProductAllocationService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
private async createSubspaces(
|
async createSubspaces(
|
||||||
subspaceData: Array<{
|
subspaceData: Array<{
|
||||||
subspaceName: string;
|
subspaceName: string;
|
||||||
space: SpaceEntity;
|
space: SpaceEntity;
|
||||||
@ -342,37 +342,26 @@ export class SubSpaceService {
|
|||||||
})),
|
})),
|
||||||
);
|
);
|
||||||
|
|
||||||
const existingSubspaces = await this.subspaceRepository.find({
|
|
||||||
where: {
|
|
||||||
uuid: In(
|
|
||||||
subspaceDtos.filter((dto) => dto.uuid).map((dto) => dto.uuid),
|
|
||||||
),
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
if (
|
|
||||||
existingSubspaces.length !==
|
|
||||||
subspaceDtos.filter((dto) => dto.uuid).length
|
|
||||||
) {
|
|
||||||
throw new HttpException(
|
|
||||||
`Some subspaces with provided UUIDs do not exist in the space.`,
|
|
||||||
HttpStatus.NOT_FOUND,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const updatedSubspaces: SubspaceEntity[] = await queryRunner.manager.save(
|
const updatedSubspaces: SubspaceEntity[] = await queryRunner.manager.save(
|
||||||
SubspaceEntity,
|
SubspaceEntity,
|
||||||
newSubspaces,
|
[
|
||||||
|
...newSubspaces,
|
||||||
|
...subspaceDtos
|
||||||
|
.filter((dto) => dto.uuid)
|
||||||
|
.map((dto) => ({
|
||||||
|
subspaceName: dto.subspaceName,
|
||||||
|
space,
|
||||||
|
})),
|
||||||
|
],
|
||||||
);
|
);
|
||||||
const allSubspaces = [...updatedSubspaces, ...existingSubspaces];
|
|
||||||
// create or update allocations for the subspaces
|
// create or update allocations for the subspaces
|
||||||
if (allSubspaces.length > 0) {
|
if (updatedSubspaces.length > 0) {
|
||||||
await this.subspaceProductAllocationService.updateSubspaceProductAllocationsV2(
|
await this.subspaceProductAllocationService.updateSubspaceProductAllocationsV2(
|
||||||
subspaceDtos.map((dto) => ({
|
subspaceDtos.map((dto) => ({
|
||||||
...dto,
|
...dto,
|
||||||
uuid:
|
uuid:
|
||||||
dto.uuid ||
|
dto.uuid ||
|
||||||
allSubspaces.find((s) => s.subspaceName === dto.subspaceName)
|
updatedSubspaces.find((s) => s.subspaceName === dto.subspaceName)
|
||||||
?.uuid,
|
?.uuid,
|
||||||
})),
|
})),
|
||||||
projectUuid,
|
projectUuid,
|
||||||
|
1
src/space/services/tag/index.ts
Normal file
1
src/space/services/tag/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './tag.service';
|
8
src/space/services/tag/tag.service.ts
Normal file
8
src/space/services/tag/tag.service.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { Injectable } from '@nestjs/common';
|
||||||
|
|
||||||
|
// todo: find out why we need to import this
|
||||||
|
// in community module in order for the whole system to work
|
||||||
|
@Injectable()
|
||||||
|
export class TagService {
|
||||||
|
constructor() {}
|
||||||
|
}
|
@ -37,6 +37,7 @@ import {
|
|||||||
} from '@app/common/modules/space-model';
|
} from '@app/common/modules/space-model';
|
||||||
import {
|
import {
|
||||||
InviteSpaceRepository,
|
InviteSpaceRepository,
|
||||||
|
SpaceLinkRepository,
|
||||||
SpaceProductAllocationRepository,
|
SpaceProductAllocationRepository,
|
||||||
SpaceRepository,
|
SpaceRepository,
|
||||||
} from '@app/common/modules/space/repositories';
|
} from '@app/common/modules/space/repositories';
|
||||||
@ -115,6 +116,7 @@ export const CommandHandlers = [DisableSpaceHandler];
|
|||||||
SubspaceRepository,
|
SubspaceRepository,
|
||||||
DeviceRepository,
|
DeviceRepository,
|
||||||
CommunityRepository,
|
CommunityRepository,
|
||||||
|
SpaceLinkRepository,
|
||||||
UserSpaceRepository,
|
UserSpaceRepository,
|
||||||
UserRepository,
|
UserRepository,
|
||||||
SpaceUserService,
|
SpaceUserService,
|
||||||
|
@ -1,7 +1,3 @@
|
|||||||
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,
|
||||||
@ -11,12 +7,10 @@ import {
|
|||||||
Param,
|
Param,
|
||||||
Patch,
|
Patch,
|
||||||
Put,
|
Put,
|
||||||
Req,
|
|
||||||
UseGuards,
|
UseGuards,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger';
|
import { UserService } from '../services/user.service';
|
||||||
import { CheckProfilePictureGuard } from 'src/guards/profile.picture.guard';
|
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||||
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,
|
||||||
@ -24,7 +18,11 @@ import {
|
|||||||
UpdateRegionDataDto,
|
UpdateRegionDataDto,
|
||||||
UpdateTimezoneDataDto,
|
UpdateTimezoneDataDto,
|
||||||
} from '../dtos';
|
} from '../dtos';
|
||||||
import { UserService } from '../services/user.service';
|
import { CheckProfilePictureGuard } from 'src/guards/profile.picture.guard';
|
||||||
|
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({
|
||||||
@ -156,32 +154,6 @@ 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,28 +1,28 @@
|
|||||||
import { CommonErrorCodes } from '@app/common/constants/error-codes.enum';
|
|
||||||
import { PermissionType } from '@app/common/constants/permission-type.enum';
|
|
||||||
import { RoleType } from '@app/common/constants/role.type.enum';
|
|
||||||
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
|
||||||
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
|
||||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
|
||||||
import {
|
|
||||||
InviteUserRepository,
|
|
||||||
InviteUserSpaceRepository,
|
|
||||||
} from '@app/common/modules/Invite-user/repositiories';
|
|
||||||
import { InviteSpaceEntity } from '@app/common/modules/space/entities/invite-space.entity';
|
|
||||||
import {
|
|
||||||
InviteSpaceRepository,
|
|
||||||
SpaceRepository,
|
|
||||||
} from '@app/common/modules/space/repositories';
|
|
||||||
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
BadRequestException,
|
||||||
HttpException,
|
HttpException,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
Injectable,
|
Injectable,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { UserDevicePermissionService } from 'src/user-device-permission/services';
|
import { UserSpaceRepository } from '@app/common/modules/user/repositories';
|
||||||
|
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||||
|
import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
||||||
import { AddUserSpaceDto, AddUserSpaceUsingCodeDto } from '../dtos';
|
import { AddUserSpaceDto, AddUserSpaceUsingCodeDto } from '../dtos';
|
||||||
|
import {
|
||||||
|
InviteSpaceRepository,
|
||||||
|
SpaceRepository,
|
||||||
|
} from '@app/common/modules/space/repositories';
|
||||||
|
import { CommonErrorCodes } from '@app/common/constants/error-codes.enum';
|
||||||
|
import { UserDevicePermissionService } from 'src/user-device-permission/services';
|
||||||
|
import { PermissionType } from '@app/common/constants/permission-type.enum';
|
||||||
|
import { InviteSpaceEntity } from '@app/common/modules/space/entities/invite-space.entity';
|
||||||
import { UserService } from './user.service';
|
import { UserService } from './user.service';
|
||||||
|
import { RoleType } from '@app/common/constants/role.type.enum';
|
||||||
|
import {
|
||||||
|
InviteUserRepository,
|
||||||
|
InviteUserSpaceRepository,
|
||||||
|
} from '@app/common/modules/Invite-user/repositiories';
|
||||||
|
import { UserStatusEnum } from '@app/common/constants/user-status.enum';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserSpaceService {
|
export class UserSpaceService {
|
||||||
@ -154,7 +154,6 @@ export class UserSpaceService {
|
|||||||
lastName: user.lastName,
|
lastName: user.lastName,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
jobTitle: null,
|
jobTitle: null,
|
||||||
companyName: null,
|
|
||||||
phoneNumber: null,
|
phoneNumber: null,
|
||||||
roleType: { uuid: user.role.uuid },
|
roleType: { uuid: user.role.uuid },
|
||||||
status: UserStatusEnum.ACTIVE,
|
status: UserStatusEnum.ACTIVE,
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
|
||||||
import { removeBase64Prefix } from '@app/common/helper/removeBase64Prefix';
|
|
||||||
import { RegionRepository } from '@app/common/modules/region/repositories';
|
|
||||||
import { TimeZoneRepository } from '@app/common/modules/timezone/repositories';
|
|
||||||
import { UserEntity } from '@app/common/modules/user/entities';
|
|
||||||
import { UserRepository } from '@app/common/modules/user/repositories';
|
|
||||||
import {
|
|
||||||
BadRequestException,
|
|
||||||
HttpException,
|
|
||||||
HttpStatus,
|
|
||||||
Injectable,
|
|
||||||
} from '@nestjs/common';
|
|
||||||
import {
|
import {
|
||||||
UpdateNameDto,
|
UpdateNameDto,
|
||||||
UpdateProfilePictureDataDto,
|
UpdateProfilePictureDataDto,
|
||||||
UpdateRegionDataDto,
|
UpdateRegionDataDto,
|
||||||
UpdateTimezoneDataDto,
|
UpdateTimezoneDataDto,
|
||||||
} from './../dtos/update.user.dto';
|
} from './../dtos/update.user.dto';
|
||||||
|
import {
|
||||||
|
BadRequestException,
|
||||||
|
HttpException,
|
||||||
|
HttpStatus,
|
||||||
|
Injectable,
|
||||||
|
} from '@nestjs/common';
|
||||||
|
import { UserRepository } from '@app/common/modules/user/repositories';
|
||||||
|
import { RegionRepository } from '@app/common/modules/region/repositories';
|
||||||
|
import { TimeZoneRepository } from '@app/common/modules/timezone/repositories';
|
||||||
|
import { removeBase64Prefix } from '@app/common/helper/removeBase64Prefix';
|
||||||
|
import { UserEntity } from '@app/common/modules/user/entities';
|
||||||
|
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class UserService {
|
export class UserService {
|
||||||
@ -269,12 +269,4 @@ 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 });
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,39 +1,39 @@
|
|||||||
import { ProductType } from '@app/common/constants/product-type.enum';
|
import { VisitorPasswordRepository } from './../../../libs/common/src/modules/visitor-password/repositories/visitor-password.repository';
|
||||||
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
|
||||||
import {
|
import {
|
||||||
BadRequestException,
|
Injectable,
|
||||||
HttpException,
|
HttpException,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
Injectable,
|
BadRequestException,
|
||||||
} from '@nestjs/common';
|
} 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 {
|
||||||
addDeviceObjectInterface,
|
addDeviceObjectInterface,
|
||||||
createTickInterface,
|
createTickInterface,
|
||||||
} from '../interfaces/visitor-password.interface';
|
} from '../interfaces/visitor-password.interface';
|
||||||
import { VisitorPasswordRepository } from './../../../libs/common/src/modules/visitor-password/repositories/visitor-password.repository';
|
import { DeviceRepository } from '@app/common/modules/device/repositories';
|
||||||
|
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 { DeviceStatuses } from '@app/common/constants/device-status.enum';
|
import { PasswordType } from '@app/common/constants/password-type.enum';
|
||||||
import {
|
import {
|
||||||
CommonHourMinutes,
|
CommonHourMinutes,
|
||||||
CommonHours,
|
CommonHours,
|
||||||
} from '@app/common/constants/hours-minutes.enum';
|
} from '@app/common/constants/hours-minutes.enum';
|
||||||
import { ORPHAN_SPACE_NAME } from '@app/common/constants/orphan-constant';
|
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||||
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 { AddDoorLockTemporaryPasswordDto } from '../dtos';
|
import { ORPHAN_SPACE_NAME } from '@app/common/constants/orphan-constant';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VisitorPasswordService {
|
export class VisitorPasswordService {
|
||||||
@ -57,67 +57,6 @@ 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,
|
||||||
@ -166,7 +105,7 @@ export class VisitorPasswordService {
|
|||||||
statusCode: HttpStatus.CREATED,
|
statusCode: HttpStatus.CREATED,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
private async addOfflineMultipleTimeTemporaryPassword(
|
async addOfflineMultipleTimeTemporaryPassword(
|
||||||
addDoorLockOfflineMultipleDto: AddDoorLockTemporaryPasswordDto,
|
addDoorLockOfflineMultipleDto: AddDoorLockTemporaryPasswordDto,
|
||||||
userUuid: string,
|
userUuid: string,
|
||||||
projectUuid: string,
|
projectUuid: string,
|
||||||
@ -230,7 +169,6 @@ export class VisitorPasswordService {
|
|||||||
success: true,
|
success: true,
|
||||||
result: createMultipleOfflinePass.result,
|
result: createMultipleOfflinePass.result,
|
||||||
deviceUuid,
|
deviceUuid,
|
||||||
deviceName: deviceDetails.name,
|
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
@ -293,7 +231,7 @@ export class VisitorPasswordService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async addOfflineOneTimeTemporaryPassword(
|
async addOfflineOneTimeTemporaryPassword(
|
||||||
addDoorLockOfflineOneTimeDto: AddDoorLockTemporaryPasswordDto,
|
addDoorLockOfflineOneTimeDto: AddDoorLockTemporaryPasswordDto,
|
||||||
userUuid: string,
|
userUuid: string,
|
||||||
projectUuid: string,
|
projectUuid: string,
|
||||||
@ -357,7 +295,6 @@ export class VisitorPasswordService {
|
|||||||
success: true,
|
success: true,
|
||||||
result: createOnceOfflinePass.result,
|
result: createOnceOfflinePass.result,
|
||||||
deviceUuid,
|
deviceUuid,
|
||||||
deviceName: deviceDetails.name,
|
|
||||||
};
|
};
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return {
|
return {
|
||||||
@ -420,7 +357,7 @@ export class VisitorPasswordService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async addOfflineTemporaryPasswordTuya(
|
async addOfflineTemporaryPasswordTuya(
|
||||||
doorLockUuid: string,
|
doorLockUuid: string,
|
||||||
type: string,
|
type: string,
|
||||||
addDoorLockOfflineMultipleDto: AddDoorLockTemporaryPasswordDto,
|
addDoorLockOfflineMultipleDto: AddDoorLockTemporaryPasswordDto,
|
||||||
@ -450,7 +387,7 @@ export class VisitorPasswordService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private async addOnlineTemporaryPasswordMultipleTime(
|
async addOnlineTemporaryPasswordMultipleTime(
|
||||||
addDoorLockOnlineMultipleDto: AddDoorLockTemporaryPasswordDto,
|
addDoorLockOnlineMultipleDto: AddDoorLockTemporaryPasswordDto,
|
||||||
userUuid: string,
|
userUuid: string,
|
||||||
projectUuid: string,
|
projectUuid: string,
|
||||||
@ -511,7 +448,6 @@ 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 {
|
||||||
@ -572,8 +508,67 @@ export class VisitorPasswordService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
async getPasswords(projectUuid: string) {
|
||||||
|
await this.validateProject(projectUuid);
|
||||||
|
|
||||||
private async addOnlineTemporaryPasswordOneTime(
|
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 addOnlineTemporaryPasswordOneTime(
|
||||||
addDoorLockOnlineOneTimeDto: AddDoorLockTemporaryPasswordDto,
|
addDoorLockOnlineOneTimeDto: AddDoorLockTemporaryPasswordDto,
|
||||||
userUuid: string,
|
userUuid: string,
|
||||||
projectUuid: string,
|
projectUuid: string,
|
||||||
@ -632,7 +627,6 @@ 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) {
|
||||||
@ -694,7 +688,7 @@ export class VisitorPasswordService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private async getTicketAndEncryptedPassword(
|
async getTicketAndEncryptedPassword(
|
||||||
doorLockUuid: string,
|
doorLockUuid: string,
|
||||||
passwordPlan: string,
|
passwordPlan: string,
|
||||||
projectUuid: string,
|
projectUuid: string,
|
||||||
@ -731,7 +725,6 @@ 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(
|
||||||
@ -741,7 +734,7 @@ export class VisitorPasswordService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async createDoorLockTicketTuya(
|
async createDoorLockTicketTuya(
|
||||||
deviceUuid: string,
|
deviceUuid: string,
|
||||||
): Promise<createTickInterface> {
|
): Promise<createTickInterface> {
|
||||||
try {
|
try {
|
||||||
@ -760,7 +753,7 @@ export class VisitorPasswordService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async addOnlineTemporaryPasswordMultipleTuya(
|
async addOnlineTemporaryPasswordMultipleTuya(
|
||||||
addDeviceObj: addDeviceObjectInterface,
|
addDeviceObj: addDeviceObjectInterface,
|
||||||
doorLockUuid: string,
|
doorLockUuid: string,
|
||||||
): Promise<createTickInterface> {
|
): Promise<createTickInterface> {
|
||||||
@ -802,7 +795,7 @@ export class VisitorPasswordService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private getWorkingDayValue(days) {
|
getWorkingDayValue(days) {
|
||||||
// Array representing the days of the week
|
// Array representing the days of the week
|
||||||
const weekDays = [
|
const weekDays = [
|
||||||
DaysEnum.SAT,
|
DaysEnum.SAT,
|
||||||
@ -834,7 +827,36 @@ export class VisitorPasswordService {
|
|||||||
|
|
||||||
return workingDayValue;
|
return workingDayValue;
|
||||||
}
|
}
|
||||||
private timeToMinutes(timeStr) {
|
getDaysFromWorkingDayValue(workingDayValue) {
|
||||||
|
// 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) {
|
||||||
@ -861,7 +883,38 @@ export class VisitorPasswordService {
|
|||||||
throw new HttpException(error.message, HttpStatus.INTERNAL_SERVER_ERROR);
|
throw new HttpException(error.message, HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private async getDeviceByDeviceUuid(
|
minutesToTime(totalMinutes) {
|
||||||
|
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,
|
||||||
@ -886,7 +939,7 @@ export class VisitorPasswordService {
|
|||||||
throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND);
|
throw new HttpException('Device Not Found', HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private async addOnlineTemporaryPasswordOneTimeTuya(
|
async addOnlineTemporaryPasswordOneTimeTuya(
|
||||||
addDeviceObj: addDeviceObjectInterface,
|
addDeviceObj: addDeviceObjectInterface,
|
||||||
doorLockUuid: string,
|
doorLockUuid: string,
|
||||||
): Promise<createTickInterface> {
|
): Promise<createTickInterface> {
|
||||||
|
Reference in New Issue
Block a user