added exception filter and removed controller error handling

This commit is contained in:
unknown
2024-10-06 11:04:25 +03:00
26 changed files with 780 additions and 1345 deletions

View File

@ -41,5 +41,5 @@ export class UserSignUpDto {
@IsString()
@IsOptional()
public regionUuid: string;
public regionUuid?: string;
}

View File

@ -1,19 +1,23 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsEmail, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { IsEmail, IsOptional, IsString } from 'class-validator';
export class UserLoginDto {
@ApiProperty()
@IsEmail()
@IsNotEmpty()
email: string;
@IsOptional()
email?: string;
@ApiProperty()
@IsString()
@IsOptional()
password: string;
password?: string;
@ApiProperty()
@IsString()
@IsOptional()
regionUuid?: string;
@IsOptional()
@IsString()
googleCode?: string;
}

View File

@ -19,6 +19,7 @@ import * as argon2 from 'argon2';
import { differenceInSeconds } from '@app/common/helper/differenceInSeconds';
import { LessThan, MoreThan } from 'typeorm';
import { ConfigService } from '@nestjs/config';
import { UUID } from 'typeorm/driver/mongodb/bson.typings';
@Injectable()
export class UserAuthService {
@ -89,13 +90,38 @@ export class UserAuthService {
async userLogin(data: UserLoginDto) {
try {
const user = await this.authService.validateUser(
data.email,
data.password,
data.regionUuid,
);
if (!user) {
throw new UnauthorizedException('Invalid login credentials.');
let user;
if (data.googleCode) {
const googleUserData = await this.authService.login({
googleCode: data.googleCode,
});
const userExists = await this.userRepository.exists({
where: {
email: googleUserData['email'],
},
});
user = await this.userRepository.findOne({
where: {
email: googleUserData['email'],
},
});
if (!userExists) {
await this.signUp({
email: googleUserData['email'],
firstName: googleUserData['given_name'],
lastName: googleUserData['family_name'],
password: googleUserData['email'],
});
}
data.email = googleUserData['email'];
data.password = googleUserData['password'];
}
if (!data.googleCode) {
user = await this.authService.validateUser(
data.email,
data.password,
data.regionUuid,
);
}
const session = await Promise.all([
await this.sessionRepository.update(
@ -110,7 +136,7 @@ export class UserAuthService {
isLoggedOut: false,
}),
]);
return await this.authService.login({
const res = await this.authService.login({
email: user.email,
userId: user.uuid,
uuid: user.uuid,
@ -119,6 +145,7 @@ export class UserAuthService {
}),
sessionId: session[1].uuid,
});
return res;
} catch (error) {
throw new BadRequestException('Invalid credentials');
}

View File

@ -4,7 +4,6 @@ import {
Controller,
Delete,
Get,
HttpException,
HttpStatus,
Param,
Post,
@ -31,52 +30,30 @@ export class AutomationController {
@UseGuards(JwtAuthGuard)
@Post()
async addAutomation(@Body() addAutomationDto: AddAutomationDto) {
try {
const automation =
await this.automationService.addAutomation(addAutomationDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Automation added successfully',
data: automation,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const automation =
await this.automationService.addAutomation(addAutomationDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Automation added successfully',
data: automation,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get(':unitUuid')
async getAutomationByUnit(@Param('unitUuid') unitUuid: string) {
try {
const automation =
await this.automationService.getAutomationByUnit(unitUuid);
return automation;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const automation =
await this.automationService.getAutomationByUnit(unitUuid);
return automation;
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('details/:automationId')
async getAutomationDetails(@Param('automationId') automationId: string) {
try {
const automation =
await this.automationService.getAutomationDetails(automationId);
return automation;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
``;
}
const automation =
await this.automationService.getAutomationDetails(automationId);
return automation;
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -85,18 +62,11 @@ export class AutomationController {
@Param('unitUuid') unitUuid: string,
@Param('automationId') automationId: string,
) {
try {
await this.automationService.deleteAutomation(unitUuid, automationId);
return {
statusCode: HttpStatus.OK,
message: 'Automation Deleted Successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.automationService.deleteAutomation(unitUuid, automationId);
return {
statusCode: HttpStatus.OK,
message: 'Automation Deleted Successfully',
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -105,23 +75,16 @@ export class AutomationController {
@Body() updateAutomationDto: UpdateAutomationDto,
@Param('automationId') automationId: string,
) {
try {
const automation = await this.automationService.updateAutomation(
updateAutomationDto,
automationId,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Automation updated successfully',
data: automation,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const automation = await this.automationService.updateAutomation(
updateAutomationDto,
automationId,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Automation updated successfully',
data: automation,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -130,21 +93,14 @@ export class AutomationController {
@Body() updateAutomationStatusDto: UpdateAutomationStatusDto,
@Param('automationId') automationId: string,
) {
try {
await this.automationService.updateAutomationStatus(
updateAutomationStatusDto,
automationId,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Automation status updated successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.automationService.updateAutomationStatus(
updateAutomationStatusDto,
automationId,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Automation status updated successfully',
};
}
}

View File

@ -3,7 +3,6 @@ import {
Body,
Controller,
Get,
HttpException,
HttpStatus,
Param,
Post,
@ -33,36 +32,21 @@ export class BuildingController {
@UseGuards(JwtAuthGuard, CheckCommunityTypeGuard)
@Post()
async addBuilding(@Body() addBuildingDto: AddBuildingDto) {
try {
const building = await this.buildingService.addBuilding(addBuildingDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Building added successfully',
data: building,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const building = await this.buildingService.addBuilding(addBuildingDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Building added successfully',
data: building,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, BuildingPermissionGuard)
@Get(':buildingUuid')
async getBuildingByUuid(@Param('buildingUuid') buildingUuid: string) {
try {
const building =
await this.buildingService.getBuildingByUuid(buildingUuid);
return building;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const building = await this.buildingService.getBuildingByUuid(buildingUuid);
return building;
}
@ApiBearerAuth()
@ -72,64 +56,36 @@ export class BuildingController {
@Param('buildingUuid') buildingUuid: string,
@Query() query: GetBuildingChildDto,
) {
try {
const building = await this.buildingService.getBuildingChildByUuid(
buildingUuid,
query,
);
return building;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const building = await this.buildingService.getBuildingChildByUuid(
buildingUuid,
query,
);
return building;
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, BuildingPermissionGuard)
@Get('parent/:buildingUuid')
async getBuildingParentByUuid(@Param('buildingUuid') buildingUuid: string) {
try {
const building =
await this.buildingService.getBuildingParentByUuid(buildingUuid);
return building;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const building =
await this.buildingService.getBuildingParentByUuid(buildingUuid);
return building;
}
@ApiBearerAuth()
@UseGuards(AdminRoleGuard, CheckUserBuildingGuard)
@Post('user')
async addUserBuilding(@Body() addUserBuildingDto: AddUserBuildingDto) {
try {
await this.buildingService.addUserBuilding(addUserBuildingDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'user building added successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.buildingService.addUserBuilding(addUserBuildingDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'user building added successfully',
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('user/:userUuid')
async getBuildingsByUserId(@Param('userUuid') userUuid: string) {
try {
return await this.buildingService.getBuildingsByUserId(userUuid);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.buildingService.getBuildingsByUserId(userUuid);
}
@ApiBearerAuth()
@ -139,17 +95,10 @@ export class BuildingController {
@Param('buildingUuid') buildingUuid: string,
@Body() updateBuildingDto: UpdateBuildingNameDto,
) {
try {
const building = await this.buildingService.renameBuildingByUuid(
buildingUuid,
updateBuildingDto,
);
return building;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const building = await this.buildingService.renameBuildingByUuid(
buildingUuid,
updateBuildingDto,
);
return building;
}
}

View File

@ -3,7 +3,6 @@ import {
Body,
Controller,
Get,
HttpException,
HttpStatus,
Param,
Post,
@ -35,51 +34,29 @@ export class CommunityController {
@UseGuards(JwtAuthGuard)
@Post()
async addCommunity(@Body() addCommunityDto: AddCommunityDto) {
try {
const community =
await this.communityService.addCommunity(addCommunityDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Community added successfully',
data: community,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const community = await this.communityService.addCommunity(addCommunityDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Community added successfully',
data: community,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get(':communityUuid')
async getCommunityByUuid(@Param('communityUuid') communityUuid: string) {
try {
const community =
await this.communityService.getCommunityByUuid(communityUuid);
return community;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const community =
await this.communityService.getCommunityByUuid(communityUuid);
return community;
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get()
async getCommunities() {
try {
const communities = await this.communityService.getCommunities();
return communities;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const communities = await this.communityService.getCommunities();
return communities;
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -88,50 +65,29 @@ export class CommunityController {
@Param('communityUuid') communityUuid: string,
@Query() query: GetCommunityChildDto,
) {
try {
const community = await this.communityService.getCommunityChildByUuid(
communityUuid,
query,
);
return community;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const community = await this.communityService.getCommunityChildByUuid(
communityUuid,
query,
);
return community;
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('user/:userUuid')
async getCommunitiesByUserId(@Param('userUuid') userUuid: string) {
try {
return await this.communityService.getCommunitiesByUserId(userUuid);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.communityService.getCommunitiesByUserId(userUuid);
}
@ApiBearerAuth()
@UseGuards(AdminRoleGuard)
@Post('user')
async addUserCommunity(@Body() addUserCommunityDto: AddUserCommunityDto) {
try {
await this.communityService.addUserCommunity(addUserCommunityDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'user community added successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.communityService.addUserCommunity(addUserCommunityDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'user community added successfully',
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -140,17 +96,10 @@ export class CommunityController {
@Param('communityUuid') communityUuid: string,
@Body() updateCommunityDto: UpdateCommunityNameDto,
) {
try {
const community = await this.communityService.renameCommunityByUuid(
communityUuid,
updateCommunityDto,
);
return community;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const community = await this.communityService.renameCommunityByUuid(
communityUuid,
updateCommunityDto,
);
return community;
}
}

View File

@ -3,7 +3,6 @@ import {
Controller,
Delete,
Get,
HttpException,
HttpStatus,
Param,
Post,
@ -31,22 +30,15 @@ export class DeviceMessagesSubscriptionController {
async addDeviceMessagesSubscription(
@Body() deviceMessagesAddDto: DeviceMessagesAddDto,
) {
try {
const addDetails =
await this.deviceMessagesSubscriptionService.addDeviceMessagesSubscription(
deviceMessagesAddDto,
);
return {
statusCode: HttpStatus.CREATED,
message: 'Device Messages Subscription Added Successfully',
data: addDetails,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
const addDetails =
await this.deviceMessagesSubscriptionService.addDeviceMessagesSubscription(
deviceMessagesAddDto,
);
}
return {
statusCode: HttpStatus.CREATED,
message: 'Device Messages Subscription Added Successfully',
data: addDetails,
};
}
@ApiBearerAuth()
@ -56,23 +48,16 @@ export class DeviceMessagesSubscriptionController {
@Param('deviceUuid') deviceUuid: string,
@Param('userUuid') userUuid: string,
) {
try {
const deviceDetails =
await this.deviceMessagesSubscriptionService.getDeviceMessagesSubscription(
userUuid,
deviceUuid,
);
return {
statusCode: HttpStatus.OK,
message: 'User Device Subscription fetched Successfully',
data: deviceDetails,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
const deviceDetails =
await this.deviceMessagesSubscriptionService.getDeviceMessagesSubscription(
userUuid,
deviceUuid,
);
}
return {
statusCode: HttpStatus.OK,
message: 'User Device Subscription fetched Successfully',
data: deviceDetails,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -80,19 +65,12 @@ export class DeviceMessagesSubscriptionController {
async deleteDeviceMessagesSubscription(
@Body() deviceMessagesAddDto: DeviceMessagesAddDto,
) {
try {
await this.deviceMessagesSubscriptionService.deleteDeviceMessagesSubscription(
deviceMessagesAddDto,
);
return {
statusCode: HttpStatus.OK,
message: 'User subscription deleted Successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.deviceMessagesSubscriptionService.deleteDeviceMessagesSubscription(
deviceMessagesAddDto,
);
return {
statusCode: HttpStatus.OK,
message: 'User subscription deleted Successfully',
};
}
}

View File

@ -6,7 +6,6 @@ import {
Post,
Query,
Param,
HttpException,
HttpStatus,
UseGuards,
Req,
@ -42,34 +41,20 @@ export class DeviceController {
@UseGuards(SuperAdminRoleGuard, CheckDeviceGuard)
@Post()
async addDeviceUser(@Body() addDeviceDto: AddDeviceDto) {
try {
const device = await this.deviceService.addDeviceUser(addDeviceDto);
const device = await this.deviceService.addDeviceUser(addDeviceDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'device added successfully',
data: device,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'device added successfully',
data: device,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('user/:userUuid')
async getDevicesByUser(@Param('userUuid') userUuid: string) {
try {
return await this.deviceService.getDevicesByUser(userUuid);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.deviceService.getDevicesByUser(userUuid);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, CheckRoomGuard)
@ -78,31 +63,17 @@ export class DeviceController {
@Query() getDeviceByRoomUuidDto: GetDeviceByRoomUuidDto,
@Req() req: any,
) {
try {
const userUuid = req.user.uuid;
return await this.deviceService.getDevicesByRoomId(
getDeviceByRoomUuidDto,
userUuid,
);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const userUuid = req.user.uuid;
return await this.deviceService.getDevicesByRoomId(
getDeviceByRoomUuidDto,
userUuid,
);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('unit/:unitUuid')
async getDevicesByUnitId(@Param('unitUuid') unitUuid: string) {
try {
return await this.deviceService.getDevicesByUnitId(unitUuid);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.deviceService.getDevicesByUnitId(unitUuid);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, CheckRoomGuard)
@ -110,23 +81,16 @@ export class DeviceController {
async updateDeviceInRoom(
@Body() updateDeviceInRoomDto: UpdateDeviceInRoomDto,
) {
try {
const device = await this.deviceService.updateDeviceInRoom(
updateDeviceInRoomDto,
);
const device = await this.deviceService.updateDeviceInRoom(
updateDeviceInRoomDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'device updated in room successfully',
data: device,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'device updated in room successfully',
data: device,
};
}
@ApiBearerAuth()
@ -136,18 +100,11 @@ export class DeviceController {
@Param('deviceUuid') deviceUuid: string,
@Req() req: any,
) {
try {
const userUuid = req.user.uuid;
return await this.deviceService.getDeviceDetailsByDeviceId(
deviceUuid,
userUuid,
);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const userUuid = req.user.uuid;
return await this.deviceService.getDeviceDetailsByDeviceId(
deviceUuid,
userUuid,
);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, CheckUserHavePermission)
@ -155,29 +112,13 @@ export class DeviceController {
async getDeviceInstructionByDeviceId(
@Param('deviceUuid') deviceUuid: string,
) {
try {
return await this.deviceService.getDeviceInstructionByDeviceId(
deviceUuid,
);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.deviceService.getDeviceInstructionByDeviceId(deviceUuid);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, CheckUserHavePermission)
@Get(':deviceUuid/functions/status')
async getDevicesInstructionStatus(@Param('deviceUuid') deviceUuid: string) {
try {
return await this.deviceService.getDevicesInstructionStatus(deviceUuid);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.deviceService.getDevicesInstructionStatus(deviceUuid);
}
@ApiBearerAuth()
@ -187,17 +128,7 @@ export class DeviceController {
@Body() controlDeviceDto: ControlDeviceDto,
@Param('deviceUuid') deviceUuid: string,
) {
try {
return await this.deviceService.controlDevice(
controlDeviceDto,
deviceUuid,
);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.deviceService.controlDevice(controlDeviceDto, deviceUuid);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -206,43 +137,22 @@ export class DeviceController {
@Param('deviceUuid') deviceUuid: string,
@Param('firmwareVersion') firmwareVersion: number,
) {
try {
return await this.deviceService.updateDeviceFirmware(
deviceUuid,
firmwareVersion,
);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.deviceService.updateDeviceFirmware(
deviceUuid,
firmwareVersion,
);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('gateway/:gatewayUuid/devices')
async getDevicesInGateway(@Param('gatewayUuid') gatewayUuid: string) {
try {
return await this.deviceService.getDevicesInGateway(gatewayUuid);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.deviceService.getDevicesInGateway(gatewayUuid);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get()
async getAllDevices() {
try {
return await this.deviceService.getAllDevices();
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.deviceService.getAllDevices();
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -251,14 +161,7 @@ export class DeviceController {
@Param('deviceUuid') deviceUuid: string,
@Query() query: GetDeviceLogsDto,
) {
try {
return await this.deviceService.getDeviceLogs(deviceUuid, query);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.deviceService.getDeviceLogs(deviceUuid, query);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -266,16 +169,7 @@ export class DeviceController {
async batchControlDevices(
@Body() batchControlDevicesDto: BatchControlDevicesDto,
) {
try {
return await this.deviceService.batchControlDevices(
batchControlDevicesDto,
);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.deviceService.batchControlDevices(batchControlDevicesDto);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -283,14 +177,7 @@ export class DeviceController {
async batchStatusDevices(
@Query() batchStatusDevicesDto: BatchStatusDevicesDto,
) {
try {
return await this.deviceService.batchStatusDevices(batchStatusDevicesDto);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.deviceService.batchStatusDevices(batchStatusDevicesDto);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -298,15 +185,8 @@ export class DeviceController {
async batchFactoryResetDevices(
@Body() batchFactoryResetDevicesDto: BatchFactoryResetDevicesDto,
) {
try {
return await this.deviceService.batchFactoryResetDevices(
batchFactoryResetDevicesDto,
);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.deviceService.batchFactoryResetDevices(
batchFactoryResetDevicesDto,
);
}
}

View File

@ -4,7 +4,6 @@ import {
Controller,
Post,
Param,
HttpException,
HttpStatus,
Get,
Delete,
@ -31,27 +30,20 @@ export class DoorLockController {
@Body() addDoorLockDto: AddDoorLockOnlineDto,
@Param('doorLockUuid') doorLockUuid: string,
) {
try {
const temporaryPassword =
await this.doorLockService.addOnlineTemporaryPassword(
addDoorLockDto,
doorLockUuid,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'online temporary password added successfully',
data: {
id: temporaryPassword.id,
},
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
const temporaryPassword =
await this.doorLockService.addOnlineTemporaryPassword(
addDoorLockDto,
doorLockUuid,
);
}
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'online temporary password added successfully',
data: {
id: temporaryPassword.id,
},
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -59,24 +51,17 @@ export class DoorLockController {
async addOfflineOneTimeTemporaryPassword(
@Param('doorLockUuid') doorLockUuid: string,
) {
try {
const temporaryPassword =
await this.doorLockService.addOfflineOneTimeTemporaryPassword(
doorLockUuid,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'offline temporary password added successfully',
data: temporaryPassword,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
const temporaryPassword =
await this.doorLockService.addOfflineOneTimeTemporaryPassword(
doorLockUuid,
);
}
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'offline temporary password added successfully',
data: temporaryPassword,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -86,25 +71,18 @@ export class DoorLockController {
addDoorLockOfflineTempMultipleTimeDto: AddDoorLockOfflineTempMultipleTimeDto,
@Param('doorLockUuid') doorLockUuid: string,
) {
try {
const temporaryPassword =
await this.doorLockService.addOfflineMultipleTimeTemporaryPassword(
addDoorLockOfflineTempMultipleTimeDto,
doorLockUuid,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'offline temporary password added successfully',
data: temporaryPassword,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
const temporaryPassword =
await this.doorLockService.addOfflineMultipleTimeTemporaryPassword(
addDoorLockOfflineTempMultipleTimeDto,
doorLockUuid,
);
}
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'offline temporary password added successfully',
data: temporaryPassword,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -112,16 +90,9 @@ export class DoorLockController {
async getOnlineTemporaryPasswords(
@Param('doorLockUuid') doorLockUuid: string,
) {
try {
return await this.doorLockService.getOnlineTemporaryPasswordsMultiple(
doorLockUuid,
);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.doorLockService.getOnlineTemporaryPasswordsMultiple(
doorLockUuid,
);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -130,21 +101,11 @@ export class DoorLockController {
@Param('doorLockUuid') doorLockUuid: string,
@Param('passwordId') passwordId: string,
) {
try {
await this.doorLockService.deleteDoorLockPassword(
doorLockUuid,
passwordId,
);
return {
statusCode: HttpStatus.OK,
message: 'Temporary Password deleted Successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.doorLockService.deleteDoorLockPassword(doorLockUuid, passwordId);
return {
statusCode: HttpStatus.OK,
message: 'Temporary Password deleted Successfully',
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -152,16 +113,9 @@ export class DoorLockController {
async getOfflineOneTimeTemporaryPasswords(
@Param('doorLockUuid') doorLockUuid: string,
) {
try {
return await this.doorLockService.getOfflineOneTimeTemporaryPasswords(
doorLockUuid,
);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.doorLockService.getOfflineOneTimeTemporaryPasswords(
doorLockUuid,
);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -169,16 +123,9 @@ export class DoorLockController {
async getOfflineMultipleTimeTemporaryPasswords(
@Param('doorLockUuid') doorLockUuid: string,
) {
try {
return await this.doorLockService.getOfflineMultipleTimeTemporaryPasswords(
doorLockUuid,
);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.doorLockService.getOfflineMultipleTimeTemporaryPasswords(
doorLockUuid,
);
}
@ApiBearerAuth()
@ -190,44 +137,30 @@ export class DoorLockController {
@Param('doorLockUuid') doorLockUuid: string,
@Param('passwordId') passwordId: string,
) {
try {
const temporaryPassword =
await this.doorLockService.updateOfflineTemporaryPassword(
updateDoorLockOfflineTempDto,
doorLockUuid,
passwordId,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'offline temporary password updated successfully',
data: temporaryPassword,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
const temporaryPassword =
await this.doorLockService.updateOfflineTemporaryPassword(
updateDoorLockOfflineTempDto,
doorLockUuid,
passwordId,
);
}
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'offline temporary password updated successfully',
data: temporaryPassword,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Post('open/:doorLockUuid')
async openDoorLock(@Param('doorLockUuid') doorLockUuid: string) {
try {
await this.doorLockService.openDoorLock(doorLockUuid);
await this.doorLockService.openDoorLock(doorLockUuid);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'door lock opened successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'door lock opened successfully',
};
}
}

View File

@ -3,7 +3,6 @@ import {
Body,
Controller,
Get,
HttpException,
HttpStatus,
Param,
Post,
@ -33,35 +32,21 @@ export class FloorController {
@UseGuards(JwtAuthGuard, CheckBuildingTypeGuard)
@Post()
async addFloor(@Body() addFloorDto: AddFloorDto) {
try {
const floor = await this.floorService.addFloor(addFloorDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Floor added successfully',
data: floor,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const floor = await this.floorService.addFloor(addFloorDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Floor added successfully',
data: floor,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, FloorPermissionGuard)
@Get(':floorUuid')
async getFloorByUuid(@Param('floorUuid') floorUuid: string) {
try {
const floor = await this.floorService.getFloorByUuid(floorUuid);
return floor;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const floor = await this.floorService.getFloorByUuid(floorUuid);
return floor;
}
@ApiBearerAuth()
@ -71,65 +56,34 @@ export class FloorController {
@Param('floorUuid') floorUuid: string,
@Query() query: GetFloorChildDto,
) {
try {
const floor = await this.floorService.getFloorChildByUuid(
floorUuid,
query,
);
return floor;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const floor = await this.floorService.getFloorChildByUuid(floorUuid, query);
return floor;
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, FloorPermissionGuard)
@Get('parent/:floorUuid')
async getFloorParentByUuid(@Param('floorUuid') floorUuid: string) {
try {
const floor = await this.floorService.getFloorParentByUuid(floorUuid);
return floor;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const floor = await this.floorService.getFloorParentByUuid(floorUuid);
return floor;
}
@ApiBearerAuth()
@UseGuards(AdminRoleGuard, CheckUserFloorGuard)
@Post('user')
async addUserFloor(@Body() addUserFloorDto: AddUserFloorDto) {
try {
await this.floorService.addUserFloor(addUserFloorDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'user floor added successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.floorService.addUserFloor(addUserFloorDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'user floor added successfully',
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('user/:userUuid')
async getFloorsByUserId(@Param('userUuid') userUuid: string) {
try {
return await this.floorService.getFloorsByUserId(userUuid);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.floorService.getFloorsByUserId(userUuid);
}
@ApiBearerAuth()
@ -139,17 +93,10 @@ export class FloorController {
@Param('floorUuid') floorUuid: string,
@Body() updateFloorNameDto: UpdateFloorNameDto,
) {
try {
const floor = await this.floorService.renameFloorByUuid(
floorUuid,
updateFloorNameDto,
);
return floor;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const floor = await this.floorService.renameFloorByUuid(
floorUuid,
updateFloorNameDto,
);
return floor;
}
}

View File

@ -1,13 +1,5 @@
import { GroupService } from '../services/group.service';
import {
Controller,
Get,
UseGuards,
Param,
HttpException,
HttpStatus,
Req,
} from '@nestjs/common';
import { Controller, Get, UseGuards, Param, Req } from '@nestjs/common';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
import { UnitPermissionGuard } from 'src/guards/unit.permission.guard';
@ -24,14 +16,7 @@ export class GroupController {
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
@Get(':unitUuid')
async getGroupsBySpaceUuid(@Param('unitUuid') unitUuid: string) {
try {
return await this.groupService.getGroupsByUnitUuid(unitUuid);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.groupService.getGroupsByUnitUuid(unitUuid);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
@ -41,19 +26,12 @@ export class GroupController {
@Param('groupName') groupName: string,
@Req() req: any,
) {
try {
const userUuid = req.user.uuid;
const userUuid = req.user.uuid;
return await this.groupService.getUnitDevicesByGroupName(
unitUuid,
groupName,
userUuid,
);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.groupService.getUnitDevicesByGroupName(
unitUuid,
groupName,
userUuid,
);
}
}

View File

@ -1,4 +1,4 @@
import { Controller, Get, HttpException, HttpStatus } from '@nestjs/common';
import { Controller, Get } from '@nestjs/common';
import { RegionService } from '../services/region.service';
import { ApiTags, ApiOperation } from '@nestjs/swagger';
import { ControllerRoute } from '@app/common/constants/controller-route';
@ -17,13 +17,6 @@ export class RegionController {
description: ControllerRoute.REGION.ACTIONS.GET_REGIONS_DESCRIPTION,
})
async getAllRegions() {
try {
return await this.regionService.getAllRegions();
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.regionService.getAllRegions();
}
}

View File

@ -2,7 +2,6 @@ import {
Body,
Controller,
Get,
HttpException,
HttpStatus,
Post,
UseGuards,
@ -23,32 +22,21 @@ export class RoleController {
@UseGuards(SuperAdminRoleGuard)
@Get('types')
async fetchRoleTypes() {
try {
const roleTypes = await this.roleService.fetchRoleTypes();
return {
statusCode: HttpStatus.OK,
message: 'Role Types fetched Successfully',
data: roleTypes,
};
} catch (err) {
throw new Error(err);
}
const roleTypes = await this.roleService.fetchRoleTypes();
return {
statusCode: HttpStatus.OK,
message: 'Role Types fetched Successfully',
data: roleTypes,
};
}
@ApiBearerAuth()
@UseGuards(SuperAdminRoleGuard)
@Post()
async addUserRoleType(@Body() addUserRoleDto: AddUserRoleDto) {
try {
await this.roleService.addUserRoleType(addUserRoleDto);
return {
statusCode: HttpStatus.OK,
message: 'User Role Added Successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.roleService.addUserRoleType(addUserRoleDto);
return {
statusCode: HttpStatus.OK,
message: 'User Role Added Successfully',
};
}
}

View File

@ -3,7 +3,6 @@ import {
Body,
Controller,
Get,
HttpException,
HttpStatus,
Param,
Post,
@ -31,81 +30,46 @@ export class RoomController {
@UseGuards(JwtAuthGuard, CheckUnitTypeGuard)
@Post()
async addRoom(@Body() addRoomDto: AddRoomDto) {
try {
const room = await this.roomService.addRoom(addRoomDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Room added successfully',
data: room,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const room = await this.roomService.addRoom(addRoomDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Room added successfully',
data: room,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, RoomPermissionGuard)
@Get(':roomUuid')
async getRoomByUuid(@Param('roomUuid') roomUuid: string) {
try {
const room = await this.roomService.getRoomByUuid(roomUuid);
return room;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const room = await this.roomService.getRoomByUuid(roomUuid);
return room;
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, RoomPermissionGuard)
@Get('parent/:roomUuid')
async getRoomParentByUuid(@Param('roomUuid') roomUuid: string) {
try {
const room = await this.roomService.getRoomParentByUuid(roomUuid);
return room;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const room = await this.roomService.getRoomParentByUuid(roomUuid);
return room;
}
@ApiBearerAuth()
@UseGuards(AdminRoleGuard, CheckUserRoomGuard)
@Post('user')
async addUserRoom(@Body() addUserRoomDto: AddUserRoomDto) {
try {
await this.roomService.addUserRoom(addUserRoomDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'user room added successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.roomService.addUserRoom(addUserRoomDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'user room added successfully',
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('user/:userUuid')
async getRoomsByUserId(@Param('userUuid') userUuid: string) {
try {
return await this.roomService.getRoomsByUserId(userUuid);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.roomService.getRoomsByUserId(userUuid);
}
@ApiBearerAuth()
@ -115,17 +79,10 @@ export class RoomController {
@Param('roomUuid') roomUuid: string,
@Body() updateRoomNameDto: UpdateRoomNameDto,
) {
try {
const room = await this.roomService.renameRoomByUuid(
roomUuid,
updateRoomNameDto,
);
return room;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const room = await this.roomService.renameRoomByUuid(
roomUuid,
updateRoomNameDto,
);
return room;
}
}

View File

@ -4,7 +4,6 @@ import {
Controller,
Delete,
Get,
HttpException,
HttpStatus,
Param,
Post,
@ -27,36 +26,22 @@ export class SceneController {
@UseGuards(JwtAuthGuard)
@Post('tap-to-run')
async addTapToRunScene(@Body() addSceneTapToRunDto: AddSceneTapToRunDto) {
try {
const tapToRunScene =
await this.sceneService.addTapToRunScene(addSceneTapToRunDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Scene added successfully',
data: tapToRunScene,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const tapToRunScene =
await this.sceneService.addTapToRunScene(addSceneTapToRunDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Scene added successfully',
data: tapToRunScene,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('tap-to-run/:unitUuid')
async getTapToRunSceneByUnit(@Param('unitUuid') unitUuid: string) {
try {
const tapToRunScenes =
await this.sceneService.getTapToRunSceneByUnit(unitUuid);
return tapToRunScenes;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const tapToRunScenes =
await this.sceneService.getTapToRunSceneByUnit(unitUuid);
return tapToRunScenes;
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -65,53 +50,31 @@ export class SceneController {
@Param('unitUuid') unitUuid: string,
@Param('sceneId') sceneId: string,
) {
try {
await this.sceneService.deleteTapToRunScene(unitUuid, sceneId);
return {
statusCode: HttpStatus.OK,
message: 'Scene Deleted Successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.sceneService.deleteTapToRunScene(unitUuid, sceneId);
return {
statusCode: HttpStatus.OK,
message: 'Scene Deleted Successfully',
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Post('tap-to-run/trigger/:sceneId')
async triggerTapToRunScene(@Param('sceneId') sceneId: string) {
try {
await this.sceneService.triggerTapToRunScene(sceneId);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Scene trigger successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.sceneService.triggerTapToRunScene(sceneId);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Scene trigger successfully',
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('tap-to-run/details/:sceneId')
async getTapToRunSceneDetails(@Param('sceneId') sceneId: string) {
try {
const tapToRunScenes =
await this.sceneService.getTapToRunSceneDetails(sceneId);
return tapToRunScenes;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
``;
}
const tapToRunScenes =
await this.sceneService.getTapToRunSceneDetails(sceneId);
return tapToRunScenes;
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -120,22 +83,15 @@ export class SceneController {
@Body() updateSceneTapToRunDto: UpdateSceneTapToRunDto,
@Param('sceneId') sceneId: string,
) {
try {
const tapToRunScene = await this.sceneService.updateTapToRunScene(
updateSceneTapToRunDto,
sceneId,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Scene updated successfully',
data: tapToRunScene,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const tapToRunScene = await this.sceneService.updateTapToRunScene(
updateSceneTapToRunDto,
sceneId,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Scene updated successfully',
data: tapToRunScene,
};
}
}

View File

@ -5,7 +5,6 @@ import {
Get,
Post,
Param,
HttpException,
HttpStatus,
UseGuards,
Put,
@ -36,24 +35,17 @@ export class ScheduleController {
@Param('deviceUuid') deviceUuid: string,
@Body() addScheduleDto: AddScheduleDto,
) {
try {
const schedule = await this.scheduleService.addDeviceSchedule(
deviceUuid,
addScheduleDto,
);
const schedule = await this.scheduleService.addDeviceSchedule(
deviceUuid,
addScheduleDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule added successfully',
data: schedule,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule added successfully',
data: schedule,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -62,17 +54,10 @@ export class ScheduleController {
@Param('deviceUuid') deviceUuid: string,
@Query() query: GetScheduleDeviceDto,
) {
try {
return await this.scheduleService.getDeviceScheduleByCategory(
deviceUuid,
query.category,
);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.scheduleService.getDeviceScheduleByCategory(
deviceUuid,
query.category,
);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -81,19 +66,12 @@ export class ScheduleController {
@Param('deviceUuid') deviceUuid: string,
@Param('scheduleId') scheduleId: string,
) {
try {
await this.scheduleService.deleteDeviceSchedule(deviceUuid, scheduleId);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule deleted successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.scheduleService.deleteDeviceSchedule(deviceUuid, scheduleId);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule deleted successfully',
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -102,22 +80,15 @@ export class ScheduleController {
@Param('deviceUuid') deviceUuid: string,
@Body() enableScheduleDto: EnableScheduleDto,
) {
try {
await this.scheduleService.enableDeviceSchedule(
deviceUuid,
enableScheduleDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule updated successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.scheduleService.enableDeviceSchedule(
deviceUuid,
enableScheduleDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule updated successfully',
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -126,23 +97,16 @@ export class ScheduleController {
@Param('deviceUuid') deviceUuid: string,
@Body() updateScheduleDto: UpdateScheduleDto,
) {
try {
const schedule = await this.scheduleService.updateDeviceSchedule(
deviceUuid,
updateScheduleDto,
);
const schedule = await this.scheduleService.updateDeviceSchedule(
deviceUuid,
updateScheduleDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule updated successfully',
data: schedule,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'schedule updated successfully',
data: schedule,
};
}
}

View File

@ -1,10 +1,4 @@
import {
Controller,
Get,
HttpException,
HttpStatus,
UseGuards,
} from '@nestjs/common';
import { Controller, Get, UseGuards } from '@nestjs/common';
import { TimeZoneService } from '../services/timezone.service';
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
import { JwtAuthGuard } from '../../../libs/common/src/guards/jwt.auth.guard';
@ -21,13 +15,6 @@ export class TimeZoneController {
@UseGuards(JwtAuthGuard)
@Get()
async getAllTimeZones() {
try {
return await this.timeZoneService.getAllTimeZones();
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.timeZoneService.getAllTimeZones();
}
}

View File

@ -3,7 +3,6 @@ import {
Body,
Controller,
Get,
HttpException,
HttpStatus,
Param,
Post,
@ -36,35 +35,21 @@ export class UnitController {
@UseGuards(JwtAuthGuard, CheckFloorTypeGuard)
@Post()
async addUnit(@Body() addUnitDto: AddUnitDto) {
try {
const unit = await this.unitService.addUnit(addUnitDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Unit added successfully',
data: unit,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const unit = await this.unitService.addUnit(addUnitDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'Unit added successfully',
data: unit,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
@Get(':unitUuid')
async getUnitByUuid(@Param('unitUuid') unitUuid: string) {
try {
const unit = await this.unitService.getUnitByUuid(unitUuid);
return unit;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const unit = await this.unitService.getUnitByUuid(unitUuid);
return unit;
}
@ApiBearerAuth()
@ -74,60 +59,32 @@ export class UnitController {
@Param('unitUuid') unitUuid: string,
@Query() query: GetUnitChildDto,
) {
try {
const unit = await this.unitService.getUnitChildByUuid(unitUuid, query);
return unit;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const unit = await this.unitService.getUnitChildByUuid(unitUuid, query);
return unit;
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
@Get('parent/:unitUuid')
async getUnitParentByUuid(@Param('unitUuid') unitUuid: string) {
try {
const unit = await this.unitService.getUnitParentByUuid(unitUuid);
return unit;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const unit = await this.unitService.getUnitParentByUuid(unitUuid);
return unit;
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, CheckUserUnitGuard)
@Post('user')
async addUserUnit(@Body() addUserUnitDto: AddUserUnitDto) {
try {
await this.unitService.addUserUnit(addUserUnitDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'user unit added successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.unitService.addUserUnit(addUserUnitDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'user unit added successfully',
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('user/:userUuid')
async getUnitsByUserId(@Param('userUuid') userUuid: string) {
try {
return await this.unitService.getUnitsByUserId(userUuid);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.unitService.getUnitsByUserId(userUuid);
}
@ApiBearerAuth()
@ -137,32 +94,18 @@ export class UnitController {
@Param('unitUuid') unitUuid: string,
@Body() updateUnitNameDto: UpdateUnitNameDto,
) {
try {
const unit = await this.unitService.renameUnitByUuid(
unitUuid,
updateUnitNameDto,
);
return unit;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const unit = await this.unitService.renameUnitByUuid(
unitUuid,
updateUnitNameDto,
);
return unit;
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, UnitPermissionGuard)
@Get(':unitUuid/invitation-code')
async getUnitInvitationCode(@Param('unitUuid') unitUuid: string) {
try {
const unit = await this.unitService.getUnitInvitationCode(unitUuid);
return unit;
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const unit = await this.unitService.getUnitInvitationCode(unitUuid);
return unit;
}
@ApiBearerAuth()
@ -171,18 +114,11 @@ export class UnitController {
async verifyCodeAndAddUserUnit(
@Body() addUserUnitUsingCodeDto: AddUserUnitUsingCodeDto,
) {
try {
await this.unitService.verifyCodeAndAddUserUnit(addUserUnitUsingCodeDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'user unit added successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.unitService.verifyCodeAndAddUserUnit(addUserUnitUsingCodeDto);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'user unit added successfully',
};
}
}

View File

@ -3,7 +3,6 @@ import {
Controller,
Delete,
Get,
HttpException,
HttpStatus,
Param,
Post,
@ -32,22 +31,14 @@ export class UserDevicePermissionController {
async addDevicePermission(
@Body() userDevicePermissionDto: UserDevicePermissionAddDto,
) {
try {
const addDetails =
await this.userDevicePermissionService.addUserPermission(
userDevicePermissionDto,
);
return {
statusCode: HttpStatus.CREATED,
message: 'User Permission for Devices Added Successfully',
data: addDetails,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const addDetails = await this.userDevicePermissionService.addUserPermission(
userDevicePermissionDto,
);
return {
statusCode: HttpStatus.CREATED,
message: 'User Permission for Devices Added Successfully',
data: addDetails,
};
}
@ApiBearerAuth()
@ -57,38 +48,27 @@ export class UserDevicePermissionController {
@Param('devicePermissionUuid') devicePermissionUuid: string,
@Body() userDevicePermissionEditDto: UserDevicePermissionEditDto,
) {
try {
await this.userDevicePermissionService.editUserPermission(
devicePermissionUuid,
userDevicePermissionEditDto,
);
return {
statusCode: HttpStatus.OK,
message: 'User Permission for Devices Updated Successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.userDevicePermissionService.editUserPermission(
devicePermissionUuid,
userDevicePermissionEditDto,
);
return {
statusCode: HttpStatus.OK,
message: 'User Permission for Devices Updated Successfully',
};
}
@ApiBearerAuth()
@UseGuards(AdminRoleGuard)
@Get(':deviceUuid/list')
async fetchDevicePermission(@Param('deviceUuid') deviceUuid: string) {
try {
const deviceDetails =
await this.userDevicePermissionService.fetchUserPermission(deviceUuid);
return {
statusCode: HttpStatus.OK,
message: 'Device Details fetched Successfully',
data: deviceDetails,
};
} catch (err) {
throw new Error(err);
}
const deviceDetails =
await this.userDevicePermissionService.fetchUserPermission(deviceUuid);
return {
statusCode: HttpStatus.OK,
message: 'Device Details fetched Successfully',
data: deviceDetails,
};
}
@ApiBearerAuth()
@UseGuards(AdminRoleGuard)
@ -96,19 +76,12 @@ export class UserDevicePermissionController {
async deleteDevicePermission(
@Param('devicePermissionUuid') devicePermissionUuid: string,
) {
try {
await this.userDevicePermissionService.deleteDevicePermission(
devicePermissionUuid,
);
return {
statusCode: HttpStatus.OK,
message: 'User Permission for Devices Deleted Successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.userDevicePermissionService.deleteDevicePermission(
devicePermissionUuid,
);
return {
statusCode: HttpStatus.OK,
message: 'User Permission for Devices Deleted Successfully',
};
}
}

View File

@ -2,7 +2,6 @@ import {
Body,
Controller,
Get,
HttpException,
HttpStatus,
Param,
Post,
@ -34,41 +33,27 @@ export class UserNotificationController {
async addUserSubscription(
@Body() userNotificationAddDto: UserNotificationAddDto,
) {
try {
const addDetails = await this.userNotificationService.addUserSubscription(
userNotificationAddDto,
);
return {
statusCode: HttpStatus.CREATED,
message: 'User Notification Added Successfully',
data: addDetails,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const addDetails = await this.userNotificationService.addUserSubscription(
userNotificationAddDto,
);
return {
statusCode: HttpStatus.CREATED,
message: 'User Notification Added Successfully',
data: addDetails,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get(':userUuid')
async fetchUserSubscriptions(@Param('userUuid') userUuid: string) {
try {
const userDetails =
await this.userNotificationService.fetchUserSubscriptions(userUuid);
return {
statusCode: HttpStatus.OK,
message: 'User Notification fetched Successfully',
data: { ...userDetails },
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const userDetails =
await this.userNotificationService.fetchUserSubscriptions(userUuid);
return {
statusCode: HttpStatus.OK,
message: 'User Notification fetched Successfully',
data: { ...userDetails },
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -76,19 +61,12 @@ export class UserNotificationController {
async updateUserSubscription(
@Body() userNotificationUpdateDto: UserNotificationUpdateDto,
) {
try {
await this.userNotificationService.updateUserSubscription(
userNotificationUpdateDto,
);
return {
statusCode: HttpStatus.OK,
message: 'User subscription updated Successfully',
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
await this.userNotificationService.updateUserSubscription(
userNotificationUpdateDto,
);
return {
statusCode: HttpStatus.OK,
message: 'User subscription updated Successfully',
};
}
}

View File

@ -3,7 +3,6 @@ import {
Controller,
Delete,
Get,
HttpException,
HttpStatus,
Param,
Put,
@ -33,14 +32,7 @@ export class UserController {
@UseGuards(JwtAuthGuard)
@Get(':userUuid')
async getUserDetailsByUserUuid(@Param('userUuid') userUuid: string) {
try {
return await this.userService.getUserDetailsByUserUuid(userUuid);
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.userService.getUserDetailsByUserUuid(userUuid);
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard, CheckProfilePictureGuard)
@ -49,23 +41,16 @@ export class UserController {
@Param('userUuid') userUuid: string,
@Body() updateProfilePictureDataDto: UpdateProfilePictureDataDto,
) {
try {
const userData = await this.userService.updateProfilePictureByUserUuid(
userUuid,
updateProfilePictureDataDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'profile picture updated successfully',
data: userData,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const userData = await this.userService.updateProfilePictureByUserUuid(
userUuid,
updateProfilePictureDataDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'profile picture updated successfully',
data: userData,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -74,23 +59,16 @@ export class UserController {
@Param('userUuid') userUuid: string,
@Body() updateRegionDataDto: UpdateRegionDataDto,
) {
try {
const userData = await this.userService.updateRegionByUserUuid(
userUuid,
updateRegionDataDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'region updated successfully',
data: userData,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const userData = await this.userService.updateRegionByUserUuid(
userUuid,
updateRegionDataDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'region updated successfully',
data: userData,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -99,23 +77,16 @@ export class UserController {
@Param('userUuid') userUuid: string,
@Body() updateTimezoneDataDto: UpdateTimezoneDataDto,
) {
try {
const userData = await this.userService.updateTimezoneByUserUuid(
userUuid,
updateTimezoneDataDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'timezone updated successfully',
data: userData,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const userData = await this.userService.updateTimezoneByUserUuid(
userUuid,
updateTimezoneDataDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'timezone updated successfully',
data: userData,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -124,23 +95,16 @@ export class UserController {
@Param('userUuid') userUuid: string,
@Body() updateNameDto: UpdateNameDto,
) {
try {
const userData = await this.userService.updateNameByUserUuid(
userUuid,
updateNameDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'name updated successfully',
data: userData,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
const userData = await this.userService.updateNameByUserUuid(
userUuid,
updateNameDto,
);
return {
statusCode: HttpStatus.CREATED,
success: true,
message: 'name updated successfully',
data: userData,
};
}
@ApiBearerAuth()
@UseGuards(SuperAdminRoleGuard)

View File

@ -3,7 +3,6 @@ import {
Body,
Controller,
Post,
HttpException,
HttpStatus,
UseGuards,
Get,
@ -34,24 +33,17 @@ export class VisitorPasswordController {
@Body() addDoorLockOnlineMultipleDto: AddDoorLockOnlineMultipleDto,
@Req() req: any,
) {
try {
const userUuid = req.user.uuid;
const temporaryPasswords =
await this.visitorPasswordService.addOnlineTemporaryPasswordMultipleTime(
addDoorLockOnlineMultipleDto,
userUuid,
);
return {
statusCode: HttpStatus.CREATED,
data: temporaryPasswords,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
const userUuid = req.user.uuid;
const temporaryPasswords =
await this.visitorPasswordService.addOnlineTemporaryPasswordMultipleTime(
addDoorLockOnlineMultipleDto,
userUuid,
);
}
return {
statusCode: HttpStatus.CREATED,
data: temporaryPasswords,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -60,24 +52,17 @@ export class VisitorPasswordController {
@Body() addDoorLockOnlineOneTimeDto: AddDoorLockOnlineOneTimeDto,
@Req() req: any,
) {
try {
const userUuid = req.user.uuid;
const temporaryPasswords =
await this.visitorPasswordService.addOnlineTemporaryPasswordOneTime(
addDoorLockOnlineOneTimeDto,
userUuid,
);
return {
statusCode: HttpStatus.CREATED,
data: temporaryPasswords,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
const userUuid = req.user.uuid;
const temporaryPasswords =
await this.visitorPasswordService.addOnlineTemporaryPasswordOneTime(
addDoorLockOnlineOneTimeDto,
userUuid,
);
}
return {
statusCode: HttpStatus.CREATED,
data: temporaryPasswords,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -86,24 +71,17 @@ export class VisitorPasswordController {
@Body() addDoorLockOfflineOneTimeDto: AddDoorLockOfflineOneTimeDto,
@Req() req: any,
) {
try {
const userUuid = req.user.uuid;
const temporaryPassword =
await this.visitorPasswordService.addOfflineOneTimeTemporaryPassword(
addDoorLockOfflineOneTimeDto,
userUuid,
);
return {
statusCode: HttpStatus.CREATED,
data: temporaryPassword,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
const userUuid = req.user.uuid;
const temporaryPassword =
await this.visitorPasswordService.addOfflineOneTimeTemporaryPassword(
addDoorLockOfflineOneTimeDto,
userUuid,
);
}
return {
statusCode: HttpStatus.CREATED,
data: temporaryPassword,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@ -113,49 +91,28 @@ export class VisitorPasswordController {
addDoorLockOfflineMultipleDto: AddDoorLockOfflineMultipleDto,
@Req() req: any,
) {
try {
const userUuid = req.user.uuid;
const temporaryPassword =
await this.visitorPasswordService.addOfflineMultipleTimeTemporaryPassword(
addDoorLockOfflineMultipleDto,
userUuid,
);
return {
statusCode: HttpStatus.CREATED,
data: temporaryPassword,
};
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
const userUuid = req.user.uuid;
const temporaryPassword =
await this.visitorPasswordService.addOfflineMultipleTimeTemporaryPassword(
addDoorLockOfflineMultipleDto,
userUuid,
);
}
return {
statusCode: HttpStatus.CREATED,
data: temporaryPassword,
};
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get()
async GetVisitorPassword() {
try {
return await this.visitorPasswordService.getPasswords();
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.visitorPasswordService.getPasswords();
}
@ApiBearerAuth()
@UseGuards(JwtAuthGuard)
@Get('/devices')
async GetVisitorDevices() {
try {
return await this.visitorPasswordService.getAllPassDevices();
} catch (error) {
throw new HttpException(
error.message || 'Internal server error',
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
);
}
return await this.visitorPasswordService.getAllPassDevices();
}
}