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

@ -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();
}
}