forked from BETAIL-BOYS/TradeFlow-API
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadmin.controller.ts
More file actions
32 lines (27 loc) · 1.05 KB
/
admin.controller.ts
File metadata and controls
32 lines (27 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { Controller, Post, Body, HttpException, HttpStatus } from '@nestjs/common';
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
import { AuthService } from './auth.service';
@ApiTags('admin')
@Controller('api/v1/admin')
export class AdminController {
constructor(private readonly authService: AuthService) {}
@Post('login')
@ApiOperation({ summary: 'Admin login for backend dashboard' })
@ApiResponse({
status: 200,
description: 'Admin login successful',
schema: { type: 'object', properties: { token: { type: 'string' } } }
})
@ApiResponse({ status: 401, description: 'Unauthorized' })
async login(@Body() body: { password: string }) {
if (!body.password) {
throw new HttpException('Password is required', HttpStatus.BAD_REQUEST);
}
const isValid = await this.authService.verifyAdminPassword(body.password);
if (!isValid) {
throw new HttpException('Invalid admin password', HttpStatus.UNAUTHORIZED);
}
const token = this.authService.generateAdminJWT();
return { token };
}
}