mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-10 23:27:31 +00:00
Merge branch 'dev'
This commit is contained in:
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 }}
|
@ -540,6 +540,15 @@ export class ControllerRoute {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static DEVICE_PROJECT = class {
|
||||||
|
public static readonly ROUTE = '/projects/:projectUuid/devices';
|
||||||
|
static ACTIONS = class {
|
||||||
|
public static readonly GET_ALL_DEVICES_SUMMARY = 'Get all devices';
|
||||||
|
public static readonly GET_ALL_DEVICES_DESCRIPTION =
|
||||||
|
'This endpoint retrieves all devices in the system.';
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
static DEVICE_PERMISSION = class {
|
static DEVICE_PERMISSION = class {
|
||||||
public static readonly ROUTE = 'device-permission';
|
public static readonly ROUTE = 'device-permission';
|
||||||
|
|
||||||
@ -680,6 +689,8 @@ export class ControllerRoute {
|
|||||||
};
|
};
|
||||||
static VISITOR_PASSWORD = class {
|
static VISITOR_PASSWORD = class {
|
||||||
public static readonly ROUTE = 'visitor-password';
|
public static readonly ROUTE = 'visitor-password';
|
||||||
|
public static readonly PROJECT_ROUTE =
|
||||||
|
'/projects/:projectUuid/visitor-password';
|
||||||
|
|
||||||
static ACTIONS = class {
|
static ACTIONS = class {
|
||||||
public static readonly ADD_ONLINE_TEMP_PASSWORD_MULTIPLE_TIME_SUMMARY =
|
public static readonly ADD_ONLINE_TEMP_PASSWORD_MULTIPLE_TIME_SUMMARY =
|
||||||
|
@ -16,6 +16,7 @@ import {
|
|||||||
} from '@app/common/modules/scene/repositories';
|
} from '@app/common/modules/scene/repositories';
|
||||||
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
|
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
|
||||||
import { AutomationRepository } from '@app/common/modules/automation/repositories';
|
import { AutomationRepository } from '@app/common/modules/automation/repositories';
|
||||||
|
import { ProjectRepository } from '@app/common/modules/project/repositiories/project.repository';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ConfigModule, SpaceRepositoryModule, DeviceStatusFirebaseModule],
|
imports: [ConfigModule, SpaceRepositoryModule, DeviceStatusFirebaseModule],
|
||||||
@ -32,6 +33,7 @@ import { AutomationRepository } from '@app/common/modules/automation/repositorie
|
|||||||
SceneRepository,
|
SceneRepository,
|
||||||
SceneDeviceRepository,
|
SceneDeviceRepository,
|
||||||
AutomationRepository,
|
AutomationRepository,
|
||||||
|
ProjectRepository,
|
||||||
],
|
],
|
||||||
exports: [AutomationService],
|
exports: [AutomationService],
|
||||||
})
|
})
|
||||||
|
29
src/device/controllers/device-project.controller.ts
Normal file
29
src/device/controllers/device-project.controller.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { DeviceService } from '../services/device.service';
|
||||||
|
import { Controller, Get, Param, UseGuards } from '@nestjs/common';
|
||||||
|
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||||
|
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||||
|
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||||
|
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
||||||
|
import { Permissions } from 'src/decorators/permissions.decorator';
|
||||||
|
import { ProjectParam } from '../dtos';
|
||||||
|
|
||||||
|
@ApiTags('Device Module')
|
||||||
|
@Controller({
|
||||||
|
version: EnableDisableStatusEnum.ENABLED,
|
||||||
|
path: ControllerRoute.DEVICE_PROJECT.ROUTE,
|
||||||
|
})
|
||||||
|
export class DeviceProjectController {
|
||||||
|
constructor(private readonly deviceService: DeviceService) {}
|
||||||
|
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@UseGuards(PermissionsGuard)
|
||||||
|
@Permissions('DEVICE_VIEW')
|
||||||
|
@Get()
|
||||||
|
@ApiOperation({
|
||||||
|
summary: ControllerRoute.DEVICE.ACTIONS.GET_ALL_DEVICES_SUMMARY,
|
||||||
|
description: ControllerRoute.DEVICE.ACTIONS.GET_ALL_DEVICES_DESCRIPTION,
|
||||||
|
})
|
||||||
|
async getAllDevices(@Param() param: ProjectParam) {
|
||||||
|
return await this.deviceService.getAllDevices(param);
|
||||||
|
}
|
||||||
|
}
|
@ -224,17 +224,6 @@ export class DeviceController {
|
|||||||
async getDevicesInGateway(@Param('gatewayUuid') gatewayUuid: string) {
|
async getDevicesInGateway(@Param('gatewayUuid') gatewayUuid: string) {
|
||||||
return await this.deviceService.getDevicesInGateway(gatewayUuid);
|
return await this.deviceService.getDevicesInGateway(gatewayUuid);
|
||||||
}
|
}
|
||||||
@ApiBearerAuth()
|
|
||||||
@UseGuards(PermissionsGuard)
|
|
||||||
@Permissions('DEVICE_VIEW')
|
|
||||||
@Get()
|
|
||||||
@ApiOperation({
|
|
||||||
summary: ControllerRoute.DEVICE.ACTIONS.GET_ALL_DEVICES_SUMMARY,
|
|
||||||
description: ControllerRoute.DEVICE.ACTIONS.GET_ALL_DEVICES_DESCRIPTION,
|
|
||||||
})
|
|
||||||
async getAllDevices() {
|
|
||||||
return await this.deviceService.getAllDevices();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
@UseGuards(PermissionsGuard)
|
@UseGuards(PermissionsGuard)
|
||||||
|
@ -20,6 +20,8 @@ import {
|
|||||||
} from '@app/common/modules/scene/repositories';
|
} from '@app/common/modules/scene/repositories';
|
||||||
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
|
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
|
||||||
import { AutomationRepository } from '@app/common/modules/automation/repositories';
|
import { AutomationRepository } from '@app/common/modules/automation/repositories';
|
||||||
|
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||||
|
import { DeviceProjectController } from './controllers/device-project.controller';
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule,
|
ConfigModule,
|
||||||
@ -28,13 +30,14 @@ import { AutomationRepository } from '@app/common/modules/automation/repositorie
|
|||||||
DeviceRepositoryModule,
|
DeviceRepositoryModule,
|
||||||
DeviceStatusFirebaseModule,
|
DeviceStatusFirebaseModule,
|
||||||
],
|
],
|
||||||
controllers: [DeviceController],
|
controllers: [DeviceController, DeviceProjectController],
|
||||||
providers: [
|
providers: [
|
||||||
DeviceService,
|
DeviceService,
|
||||||
ProductRepository,
|
ProductRepository,
|
||||||
DeviceUserPermissionRepository,
|
DeviceUserPermissionRepository,
|
||||||
PermissionTypeRepository,
|
PermissionTypeRepository,
|
||||||
SpaceRepository,
|
SpaceRepository,
|
||||||
|
ProjectRepository,
|
||||||
DeviceRepository,
|
DeviceRepository,
|
||||||
UserRepository,
|
UserRepository,
|
||||||
TuyaService,
|
TuyaService,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
export * from './add.device.dto';
|
export * from './add.device.dto';
|
||||||
export * from './control.device.dto';
|
export * from './control.device.dto';
|
||||||
export * from './get.device.dto';
|
export * from './get.device.dto';
|
||||||
|
export * from './project.param.dto';
|
||||||
|
11
src/device/dtos/project.param.dto.ts
Normal file
11
src/device/dtos/project.param.dto.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { IsUUID } from 'class-validator';
|
||||||
|
|
||||||
|
export class ProjectParam {
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'UUID of the project this community belongs to',
|
||||||
|
example: 'd290f1ee-6c54-4b01-90e6-d701748f0851',
|
||||||
|
})
|
||||||
|
@IsUUID()
|
||||||
|
projectUuid: string;
|
||||||
|
}
|
@ -60,6 +60,8 @@ import { BaseResponseDto } from '@app/common/dto/base.response.dto';
|
|||||||
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
import { SuccessResponseDto } from '@app/common/dto/success.response.dto';
|
||||||
import { DeleteSceneFromSceneDeviceDto } from '../dtos/delete.device.dto';
|
import { DeleteSceneFromSceneDeviceDto } from '../dtos/delete.device.dto';
|
||||||
import { DeviceEntity } from '@app/common/modules/device/entities';
|
import { DeviceEntity } from '@app/common/modules/device/entities';
|
||||||
|
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||||
|
import { ProjectParam } from '../dtos';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class DeviceService {
|
export class DeviceService {
|
||||||
@ -74,6 +76,7 @@ export class DeviceService {
|
|||||||
@Inject(forwardRef(() => SceneService))
|
@Inject(forwardRef(() => SceneService))
|
||||||
private readonly sceneService: SceneService,
|
private readonly sceneService: SceneService,
|
||||||
private readonly tuyaService: TuyaService,
|
private readonly tuyaService: TuyaService,
|
||||||
|
private readonly projectRepository: ProjectRepository,
|
||||||
) {
|
) {
|
||||||
const accessKey = this.configService.get<string>('auth-config.ACCESS_KEY');
|
const accessKey = this.configService.get<string>('auth-config.ACCESS_KEY');
|
||||||
const secretKey = this.configService.get<string>('auth-config.SECRET_KEY');
|
const secretKey = this.configService.get<string>('auth-config.SECRET_KEY');
|
||||||
@ -950,10 +953,19 @@ export class DeviceService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async getAllDevices(): Promise<GetDeviceDetailsInterface[]> {
|
async getAllDevices(
|
||||||
|
param: ProjectParam,
|
||||||
|
): Promise<GetDeviceDetailsInterface[]> {
|
||||||
try {
|
try {
|
||||||
|
await this.validateProject(param.projectUuid);
|
||||||
|
|
||||||
const devices = await this.deviceRepository.find({
|
const devices = await this.deviceRepository.find({
|
||||||
where: { isActive: true },
|
where: {
|
||||||
|
isActive: true,
|
||||||
|
spaceDevice: {
|
||||||
|
community: { project: { uuid: param.projectUuid } },
|
||||||
|
},
|
||||||
|
},
|
||||||
relations: [
|
relations: [
|
||||||
'spaceDevice.parent',
|
'spaceDevice.parent',
|
||||||
'spaceDevice.community',
|
'spaceDevice.community',
|
||||||
@ -1490,4 +1502,17 @@ export class DeviceService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async validateProject(uuid: string) {
|
||||||
|
const project = await this.projectRepository.findOne({
|
||||||
|
where: { uuid },
|
||||||
|
});
|
||||||
|
if (!project) {
|
||||||
|
throw new HttpException(
|
||||||
|
`A project with the uuid '${uuid}' doesn't exists.`,
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return project;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@ import {
|
|||||||
} from '@app/common/modules/scene/repositories';
|
} from '@app/common/modules/scene/repositories';
|
||||||
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
|
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
|
||||||
import { AutomationRepository } from '@app/common/modules/automation/repositories';
|
import { AutomationRepository } from '@app/common/modules/automation/repositories';
|
||||||
|
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ConfigModule, DeviceRepositoryModule],
|
imports: [ConfigModule, DeviceRepositoryModule],
|
||||||
controllers: [DoorLockController],
|
controllers: [DoorLockController],
|
||||||
@ -32,6 +33,7 @@ import { AutomationRepository } from '@app/common/modules/automation/repositorie
|
|||||||
DeviceStatusFirebaseService,
|
DeviceStatusFirebaseService,
|
||||||
SpaceRepository,
|
SpaceRepository,
|
||||||
DeviceStatusLogRepository,
|
DeviceStatusLogRepository,
|
||||||
|
ProjectRepository,
|
||||||
TuyaService,
|
TuyaService,
|
||||||
SceneService,
|
SceneService,
|
||||||
SceneIconRepository,
|
SceneIconRepository,
|
||||||
|
@ -15,6 +15,7 @@ import {
|
|||||||
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
import { TuyaService } from '@app/common/integrations/tuya/services/tuya.service';
|
||||||
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
|
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
|
||||||
import { AutomationRepository } from '@app/common/modules/automation/repositories';
|
import { AutomationRepository } from '@app/common/modules/automation/repositories';
|
||||||
|
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ConfigModule, SpaceRepositoryModule, DeviceStatusFirebaseModule],
|
imports: [ConfigModule, SpaceRepositoryModule, DeviceStatusFirebaseModule],
|
||||||
@ -28,6 +29,7 @@ import { AutomationRepository } from '@app/common/modules/automation/repositorie
|
|||||||
ProductRepository,
|
ProductRepository,
|
||||||
SceneIconRepository,
|
SceneIconRepository,
|
||||||
SceneRepository,
|
SceneRepository,
|
||||||
|
ProjectRepository,
|
||||||
SceneDeviceRepository,
|
SceneDeviceRepository,
|
||||||
AutomationRepository,
|
AutomationRepository,
|
||||||
],
|
],
|
||||||
|
@ -30,7 +30,7 @@ export class UserService {
|
|||||||
where: {
|
where: {
|
||||||
uuid: userUuid,
|
uuid: userUuid,
|
||||||
},
|
},
|
||||||
relations: ['region', 'timezone', 'roleType'],
|
relations: ['region', 'timezone', 'roleType', 'project'],
|
||||||
});
|
});
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new BadRequestException('Invalid room UUID');
|
throw new BadRequestException('Invalid room UUID');
|
||||||
@ -52,6 +52,7 @@ export class UserService {
|
|||||||
hasAcceptedAppAgreement: user?.hasAcceptedAppAgreement,
|
hasAcceptedAppAgreement: user?.hasAcceptedAppAgreement,
|
||||||
appAgreementAcceptedAt: user?.appAgreementAcceptedAt,
|
appAgreementAcceptedAt: user?.appAgreementAcceptedAt,
|
||||||
role: user?.roleType,
|
role: user?.roleType,
|
||||||
|
project: user?.project,
|
||||||
};
|
};
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err instanceof BadRequestException) {
|
if (err instanceof BadRequestException) {
|
||||||
|
@ -1 +1,2 @@
|
|||||||
export * from './visitor-password.controller';
|
export * from './visitor-password.controller';
|
||||||
|
export * from './project-visitor-password.controller';
|
@ -0,0 +1,48 @@
|
|||||||
|
import { VisitorPasswordService } from '../services/visitor-password.service';
|
||||||
|
import { Controller, UseGuards, Get, Param } from '@nestjs/common';
|
||||||
|
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||||
|
import { Permissions } from 'src/decorators/permissions.decorator';
|
||||||
|
|
||||||
|
import { EnableDisableStatusEnum } from '@app/common/constants/days.enum';
|
||||||
|
import { ControllerRoute } from '@app/common/constants/controller-route';
|
||||||
|
import { ProjectParam } from 'src/community/dtos';
|
||||||
|
import { PermissionsGuard } from 'src/guards/permissions.guard';
|
||||||
|
|
||||||
|
@ApiTags('Visitor Password Module')
|
||||||
|
@Controller({
|
||||||
|
version: EnableDisableStatusEnum.ENABLED,
|
||||||
|
path: ControllerRoute.VISITOR_PASSWORD.PROJECT_ROUTE,
|
||||||
|
})
|
||||||
|
export class VisitorPasswordProjectController {
|
||||||
|
constructor(
|
||||||
|
private readonly visitorPasswordService: VisitorPasswordService,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@UseGuards(PermissionsGuard)
|
||||||
|
@Permissions('VISITOR_PASSWORD_ADD')
|
||||||
|
@Get()
|
||||||
|
@ApiOperation({
|
||||||
|
summary:
|
||||||
|
ControllerRoute.VISITOR_PASSWORD.ACTIONS.GET_VISITOR_PASSWORD_SUMMARY,
|
||||||
|
description:
|
||||||
|
ControllerRoute.VISITOR_PASSWORD.ACTIONS.GET_VISITOR_PASSWORD_DESCRIPTION,
|
||||||
|
})
|
||||||
|
async GetVisitorPassword(@Param() param: ProjectParam) {
|
||||||
|
return await this.visitorPasswordService.getPasswords(param);
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiBearerAuth()
|
||||||
|
@UseGuards(PermissionsGuard)
|
||||||
|
@Permissions('VISITOR_PASSWORD_VIEW')
|
||||||
|
@Get('/devices')
|
||||||
|
@ApiOperation({
|
||||||
|
summary:
|
||||||
|
ControllerRoute.VISITOR_PASSWORD.ACTIONS.GET_VISITOR_DEVICES_SUMMARY,
|
||||||
|
description:
|
||||||
|
ControllerRoute.VISITOR_PASSWORD.ACTIONS.GET_VISITOR_DEVICES_DESCRIPTION,
|
||||||
|
})
|
||||||
|
async GetVisitorDevices(@Param() param: ProjectParam) {
|
||||||
|
return await this.visitorPasswordService.getAllPassDevices(param);
|
||||||
|
}
|
||||||
|
}
|
@ -5,7 +5,6 @@ import {
|
|||||||
Post,
|
Post,
|
||||||
HttpStatus,
|
HttpStatus,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
Get,
|
|
||||||
Req,
|
Req,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
import { ApiTags, ApiBearerAuth, ApiOperation } from '@nestjs/swagger';
|
||||||
@ -146,32 +145,4 @@ export class VisitorPasswordController {
|
|||||||
data: temporaryPassword,
|
data: temporaryPassword,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiBearerAuth()
|
|
||||||
@UseGuards(PermissionsGuard)
|
|
||||||
@Permissions('VISITOR_PASSWORD_VIEW')
|
|
||||||
@Get()
|
|
||||||
@ApiOperation({
|
|
||||||
summary:
|
|
||||||
ControllerRoute.VISITOR_PASSWORD.ACTIONS.GET_VISITOR_PASSWORD_SUMMARY,
|
|
||||||
description:
|
|
||||||
ControllerRoute.VISITOR_PASSWORD.ACTIONS.GET_VISITOR_PASSWORD_DESCRIPTION,
|
|
||||||
})
|
|
||||||
async GetVisitorPassword() {
|
|
||||||
return await this.visitorPasswordService.getPasswords();
|
|
||||||
}
|
|
||||||
|
|
||||||
@ApiBearerAuth()
|
|
||||||
@UseGuards(PermissionsGuard)
|
|
||||||
@Permissions('VISITOR_PASSWORD_VIEW')
|
|
||||||
@Get('/devices')
|
|
||||||
@ApiOperation({
|
|
||||||
summary:
|
|
||||||
ControllerRoute.VISITOR_PASSWORD.ACTIONS.GET_VISITOR_DEVICES_SUMMARY,
|
|
||||||
description:
|
|
||||||
ControllerRoute.VISITOR_PASSWORD.ACTIONS.GET_VISITOR_DEVICES_DESCRIPTION,
|
|
||||||
})
|
|
||||||
async GetVisitorDevices() {
|
|
||||||
return await this.visitorPasswordService.getAllPassDevices();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1 +1,2 @@
|
|||||||
export * from './temp-pass.dto';
|
export * from './temp-pass.dto';
|
||||||
|
export * from './project.param.dto';
|
11
src/vistor-password/dtos/project.param.dto.ts
Normal file
11
src/vistor-password/dtos/project.param.dto.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { ApiProperty } from '@nestjs/swagger';
|
||||||
|
import { IsUUID } from 'class-validator';
|
||||||
|
|
||||||
|
export class ProjectParam {
|
||||||
|
@ApiProperty({
|
||||||
|
description: 'UUID of the project this community belongs to',
|
||||||
|
example: 'd290f1ee-6c54-4b01-90e6-d701748f0851',
|
||||||
|
})
|
||||||
|
@IsUUID()
|
||||||
|
projectUuid: string;
|
||||||
|
}
|
@ -14,6 +14,7 @@ import {
|
|||||||
AddDoorLockOfflineOneTimeDto,
|
AddDoorLockOfflineOneTimeDto,
|
||||||
AddDoorLockOnlineMultipleDto,
|
AddDoorLockOnlineMultipleDto,
|
||||||
AddDoorLockOnlineOneTimeDto,
|
AddDoorLockOnlineOneTimeDto,
|
||||||
|
ProjectParam,
|
||||||
} from '../dtos';
|
} from '../dtos';
|
||||||
import { EmailService } from '@app/common/util/email.service';
|
import { EmailService } from '@app/common/util/email.service';
|
||||||
import { PasswordEncryptionService } from 'src/door-lock/services/encryption.services';
|
import { PasswordEncryptionService } from 'src/door-lock/services/encryption.services';
|
||||||
@ -30,6 +31,7 @@ import {
|
|||||||
CommonHourMinutes,
|
CommonHourMinutes,
|
||||||
CommonHours,
|
CommonHours,
|
||||||
} from '@app/common/constants/hours-minutes.enum';
|
} from '@app/common/constants/hours-minutes.enum';
|
||||||
|
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VisitorPasswordService {
|
export class VisitorPasswordService {
|
||||||
@ -42,6 +44,7 @@ export class VisitorPasswordService {
|
|||||||
private readonly doorLockService: DoorLockService,
|
private readonly doorLockService: DoorLockService,
|
||||||
private readonly deviceService: DeviceService,
|
private readonly deviceService: DeviceService,
|
||||||
private readonly passwordEncryptionService: PasswordEncryptionService,
|
private readonly passwordEncryptionService: PasswordEncryptionService,
|
||||||
|
private readonly projectRepository: ProjectRepository,
|
||||||
) {
|
) {
|
||||||
const accessKey = this.configService.get<string>('auth-config.ACCESS_KEY');
|
const accessKey = this.configService.get<string>('auth-config.ACCESS_KEY');
|
||||||
const secretKey = this.configService.get<string>('auth-config.SECRET_KEY');
|
const secretKey = this.configService.get<string>('auth-config.SECRET_KEY');
|
||||||
@ -444,12 +447,21 @@ export class VisitorPasswordService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async getPasswords() {
|
async getPasswords(param: ProjectParam) {
|
||||||
|
await this.validateProject(param.projectUuid);
|
||||||
|
|
||||||
const deviceIds = await this.deviceRepository.find({
|
const deviceIds = await this.deviceRepository.find({
|
||||||
where: {
|
where: {
|
||||||
productDevice: {
|
productDevice: {
|
||||||
prodType: ProductType.DL,
|
prodType: ProductType.DL,
|
||||||
},
|
},
|
||||||
|
spaceDevice: {
|
||||||
|
community: {
|
||||||
|
project: {
|
||||||
|
uuid: param.projectUuid,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
isActive: true,
|
isActive: true,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@ -487,15 +499,25 @@ export class VisitorPasswordService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAllPassDevices() {
|
async getAllPassDevices(param: ProjectParam) {
|
||||||
|
await this.validateProject(param.projectUuid);
|
||||||
|
|
||||||
const devices = await this.deviceRepository.find({
|
const devices = await this.deviceRepository.find({
|
||||||
where: {
|
where: {
|
||||||
productDevice: {
|
productDevice: {
|
||||||
prodType: ProductType.DL,
|
prodType: ProductType.DL,
|
||||||
},
|
},
|
||||||
|
spaceDevice: {
|
||||||
|
community: {
|
||||||
|
project: {
|
||||||
|
uuid: param.projectUuid,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
isActive: true,
|
isActive: true,
|
||||||
},
|
},
|
||||||
relations: ['productDevice'],
|
|
||||||
|
relations: ['productDevice', 'spaceDevice'],
|
||||||
});
|
});
|
||||||
const devicesData = await Promise.all(
|
const devicesData = await Promise.all(
|
||||||
devices?.map(async (device) => {
|
devices?.map(async (device) => {
|
||||||
@ -509,6 +531,7 @@ export class VisitorPasswordService {
|
|||||||
productType: device.productDevice.prodType,
|
productType: device.productDevice.prodType,
|
||||||
...deviceDetails,
|
...deviceDetails,
|
||||||
uuid: device.uuid,
|
uuid: device.uuid,
|
||||||
|
spaceName: device.spaceDevice.spaceName,
|
||||||
} as GetDeviceDetailsInterface;
|
} as GetDeviceDetailsInterface;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(
|
console.error(
|
||||||
@ -907,4 +930,17 @@ export class VisitorPasswordService {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async validateProject(uuid: string) {
|
||||||
|
const project = await this.projectRepository.findOne({
|
||||||
|
where: { uuid },
|
||||||
|
});
|
||||||
|
if (!project) {
|
||||||
|
throw new HttpException(
|
||||||
|
`A project with the uuid '${uuid}' doesn't exists.`,
|
||||||
|
HttpStatus.BAD_REQUEST,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return project;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,9 +21,11 @@ import {
|
|||||||
} from '@app/common/modules/scene/repositories';
|
} from '@app/common/modules/scene/repositories';
|
||||||
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
|
import { SceneDeviceRepository } from '@app/common/modules/scene-device/repositories';
|
||||||
import { AutomationRepository } from '@app/common/modules/automation/repositories';
|
import { AutomationRepository } from '@app/common/modules/automation/repositories';
|
||||||
|
import { ProjectRepository } from '@app/common/modules/project/repositiories';
|
||||||
|
import { VisitorPasswordProjectController } from './controllers';
|
||||||
@Module({
|
@Module({
|
||||||
imports: [ConfigModule, DeviceRepositoryModule, DoorLockModule],
|
imports: [ConfigModule, DeviceRepositoryModule, DoorLockModule],
|
||||||
controllers: [VisitorPasswordController],
|
controllers: [VisitorPasswordController, VisitorPasswordProjectController],
|
||||||
providers: [
|
providers: [
|
||||||
VisitorPasswordService,
|
VisitorPasswordService,
|
||||||
EmailService,
|
EmailService,
|
||||||
@ -41,6 +43,7 @@ import { AutomationRepository } from '@app/common/modules/automation/repositorie
|
|||||||
SceneRepository,
|
SceneRepository,
|
||||||
SceneDeviceRepository,
|
SceneDeviceRepository,
|
||||||
AutomationRepository,
|
AutomationRepository,
|
||||||
|
ProjectRepository,
|
||||||
],
|
],
|
||||||
exports: [VisitorPasswordService],
|
exports: [VisitorPasswordService],
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user