mirror of
https://github.com/SyncrowIOT/backend.git
synced 2025-07-16 02:36:19 +00:00
Add Door Lock Controller with temporary password functionality
This commit is contained in:
182
src/door-lock/controllers/door.lock.controller.ts
Normal file
182
src/door-lock/controllers/door.lock.controller.ts
Normal file
@ -0,0 +1,182 @@
|
||||
import { DoorLockService } from '../services/door.lock.service';
|
||||
import {
|
||||
Body,
|
||||
Controller,
|
||||
Post,
|
||||
Param,
|
||||
HttpException,
|
||||
HttpStatus,
|
||||
Get,
|
||||
Delete,
|
||||
UseGuards,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags, ApiBearerAuth } from '@nestjs/swagger';
|
||||
import { AddDoorLockOnlineDto } from '../dtos/add.online-temp.dto';
|
||||
import { AddDoorLockOfflineTempDto } from '../dtos/add.offline-temp.dto';
|
||||
import { JwtAuthGuard } from '@app/common/guards/jwt.auth.guard';
|
||||
|
||||
@ApiTags('Door Lock Module')
|
||||
@Controller({
|
||||
version: '1',
|
||||
path: 'door-lock',
|
||||
})
|
||||
export class DoorLockController {
|
||||
constructor(private readonly doorLockService: DoorLockService) {}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('temporary-password/online/:doorLockUuid')
|
||||
async addOnlineTemporaryPassword(
|
||||
@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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('temporary-password/offline/one-time/:doorLockUuid')
|
||||
async addOfflineOneTimeTemporaryPassword(
|
||||
@Body() addDoorLockOfflineTempDto: AddDoorLockOfflineTempDto,
|
||||
@Param('doorLockUuid') doorLockUuid: string,
|
||||
) {
|
||||
try {
|
||||
const temporaryPassword =
|
||||
await this.doorLockService.addOfflineOneTimeTemporaryPassword(
|
||||
addDoorLockOfflineTempDto,
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Post('temporary-password/offline/multiple-time/:doorLockUuid')
|
||||
async addOfflineMultipleTimeTemporaryPassword(
|
||||
@Body() addDoorLockOfflineTempDto: AddDoorLockOfflineTempDto,
|
||||
@Param('doorLockUuid') doorLockUuid: string,
|
||||
) {
|
||||
try {
|
||||
const temporaryPassword =
|
||||
await this.doorLockService.addOfflineMultipleTimeTemporaryPassword(
|
||||
addDoorLockOfflineTempDto,
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('temporary-password/online/:doorLockUuid')
|
||||
async getOnlineTemporaryPasswords(
|
||||
@Param('doorLockUuid') doorLockUuid: string,
|
||||
) {
|
||||
try {
|
||||
return await this.doorLockService.getOnlineTemporaryPasswords(
|
||||
doorLockUuid,
|
||||
);
|
||||
} catch (error) {
|
||||
throw new HttpException(
|
||||
error.message || 'Internal server error',
|
||||
error.status || HttpStatus.INTERNAL_SERVER_ERROR,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('temporary-password/offline/one-time/:doorLockUuid')
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Get('temporary-password/offline/multiple-time/:doorLockUuid')
|
||||
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,
|
||||
);
|
||||
}
|
||||
}
|
||||
@ApiBearerAuth()
|
||||
@UseGuards(JwtAuthGuard)
|
||||
@Delete('temporary-password/:doorLockUuid/:passwordId')
|
||||
async deleteDoorLockPassword(
|
||||
@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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
1
src/door-lock/controllers/index.ts
Normal file
1
src/door-lock/controllers/index.ts
Normal file
@ -0,0 +1 @@
|
||||
export * from './door.lock.controller';
|
Reference in New Issue
Block a user