mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 18:56:22 +00:00
149 lines
4.0 KiB
TypeScript
149 lines
4.0 KiB
TypeScript
import { VisitorPasswordService } from '../services/visitor-password.service';
|
|
import {
|
|
Body,
|
|
Controller,
|
|
Post,
|
|
HttpException,
|
|
HttpStatus,
|
|
UseGuards,
|
|
Get,
|
|
} from '@nestjs/common';
|
|
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
|
import {
|
|
AddDoorLockOfflineMultipleDto,
|
|
AddDoorLockOfflineOneTimeDto,
|
|
AddDoorLockOnlineMultipleDto,
|
|
AddDoorLockOnlineOneTimeDto,
|
|
} from '../dtos/temp-pass.dto';
|
|
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
|
|
|
@ApiTags('Visitor Password Module')
|
|
@Controller({
|
|
version: '1',
|
|
path: 'visitor-password',
|
|
})
|
|
export class VisitorPasswordController {
|
|
constructor(
|
|
private readonly visitorPasswordService: VisitorPasswordService,
|
|
) {}
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Post('temporary-password/online/multiple-time')
|
|
async addOnlineTemporaryPasswordMultipleTime(
|
|
@Body() addDoorLockOnlineMultipleDto: AddDoorLockOnlineMultipleDto,
|
|
) {
|
|
try {
|
|
const temporaryPasswords =
|
|
await this.visitorPasswordService.addOnlineTemporaryPasswordMultipleTime(
|
|
addDoorLockOnlineMultipleDto,
|
|
);
|
|
|
|
return {
|
|
statusCode: HttpStatus.CREATED,
|
|
data: temporaryPasswords,
|
|
};
|
|
} catch (error) {
|
|
throw new HttpException(
|
|
error.message || 'Internal server error',
|
|
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
|
);
|
|
}
|
|
}
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Post('temporary-password/online/one-time')
|
|
async addOnlineTemporaryPassword(
|
|
@Body() addDoorLockOnlineOneTimeDto: AddDoorLockOnlineOneTimeDto,
|
|
) {
|
|
try {
|
|
const temporaryPasswords =
|
|
await this.visitorPasswordService.addOnlineTemporaryPasswordOneTime(
|
|
addDoorLockOnlineOneTimeDto,
|
|
);
|
|
|
|
return {
|
|
statusCode: HttpStatus.CREATED,
|
|
data: temporaryPasswords,
|
|
};
|
|
} catch (error) {
|
|
throw new HttpException(
|
|
error.message || 'Internal server error',
|
|
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
|
);
|
|
}
|
|
}
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Post('temporary-password/offline/one-time')
|
|
async addOfflineOneTimeTemporaryPassword(
|
|
@Body() addDoorLockOfflineOneTimeDto: AddDoorLockOfflineOneTimeDto,
|
|
) {
|
|
try {
|
|
const temporaryPassword =
|
|
await this.visitorPasswordService.addOfflineOneTimeTemporaryPassword(
|
|
addDoorLockOfflineOneTimeDto,
|
|
);
|
|
|
|
return {
|
|
statusCode: HttpStatus.CREATED,
|
|
data: temporaryPassword,
|
|
};
|
|
} catch (error) {
|
|
throw new HttpException(
|
|
error.message || 'Internal server error',
|
|
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
|
);
|
|
}
|
|
}
|
|
@ApiBearerAuth()
|
|
@UseGuards(JwtAuthGuard)
|
|
@Post('temporary-password/offline/multiple-time')
|
|
async addOfflineMultipleTimeTemporaryPassword(
|
|
@Body()
|
|
addDoorLockOfflineMultipleDto: AddDoorLockOfflineMultipleDto,
|
|
) {
|
|
try {
|
|
const temporaryPassword =
|
|
await this.visitorPasswordService.addOfflineMultipleTimeTemporaryPassword(
|
|
addDoorLockOfflineMultipleDto,
|
|
);
|
|
|
|
return {
|
|
statusCode: HttpStatus.CREATED,
|
|
data: temporaryPassword,
|
|
};
|
|
} catch (error) {
|
|
throw new HttpException(
|
|
error.message || 'Internal server error',
|
|
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
|
);
|
|
}
|
|
}
|
|
@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,
|
|
);
|
|
}
|
|
}
|
|
@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,
|
|
);
|
|
}
|
|
}
|
|
}
|