forked from hangshuo652/aurak
0a9588abb7
- Add pagination support to findAll (page, limit query params) - Add findByTemplateId method to service - Add GET /by-template/:templateId endpoint to controller - Service already includes CRUD for QuestionBank and QuestionBankItem
38 lines
1.0 KiB
TypeScript
38 lines
1.0 KiB
TypeScript
import { Controller, Get, Post, Request, UseGuards } from '@nestjs/common';
|
|
import { AuthService } from './auth.service';
|
|
import { LocalAuthGuard } from './local-auth.guard';
|
|
import { CombinedAuthGuard } from './combined-auth.guard';
|
|
import { Public } from './public.decorator';
|
|
|
|
@Controller('auth')
|
|
export class AuthController {
|
|
constructor(private authService: AuthService) {}
|
|
|
|
@Public()
|
|
@UseGuards(LocalAuthGuard)
|
|
@Post('login')
|
|
async login(@Request() req) {
|
|
return this.authService.login(req.user);
|
|
}
|
|
|
|
@UseGuards(CombinedAuthGuard)
|
|
@Get('profile')
|
|
getProfile(@Request() req) {
|
|
return req.user;
|
|
}
|
|
|
|
@UseGuards(CombinedAuthGuard)
|
|
@Get('api-key')
|
|
async getApiKey(@Request() req) {
|
|
const apiKey = await this.authService.getOrCreateApiKey(req.user.id);
|
|
return { apiKey };
|
|
}
|
|
|
|
@UseGuards(CombinedAuthGuard)
|
|
@Post('api-key/regenerate')
|
|
async regenerateApiKey(@Request() req) {
|
|
const apiKey = await this.authService.regenerateApiKey(req.user.id);
|
|
return { apiKey };
|
|
}
|
|
}
|