41 lines
1012 B
TypeScript
41 lines
1012 B
TypeScript
import { Controller, Post, Body } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation } from '@nestjs/swagger';
|
|
|
|
import { LoginDto } from '../dto/login.dto';
|
|
import { LoginHandler } from '../../application/handlers/login.handler';
|
|
import { TokenHandler } from '../../application/handlers/token.handler';
|
|
|
|
@ApiTags('Auth')
|
|
@Controller('api/v1/auth')
|
|
export class AuthController {
|
|
constructor(
|
|
private readonly loginHandler: LoginHandler,
|
|
private readonly tokenHandler: TokenHandler,
|
|
) {}
|
|
|
|
@Post('login')
|
|
@ApiOperation({ summary: 'Login and obtain access token' })
|
|
async login(@Body() dto: LoginDto) {
|
|
const data = await this.loginHandler.execute(dto);
|
|
|
|
return {
|
|
success: true,
|
|
data,
|
|
meta: {},
|
|
};
|
|
}
|
|
|
|
@Post('token')
|
|
@ApiOperation({ summary: 'Obtain access token using client credentials' })
|
|
async token(@Body() body: any) {
|
|
const data = await this.tokenHandler.execute(body);
|
|
|
|
return {
|
|
success: true,
|
|
data,
|
|
meta: {},
|
|
};
|
|
}
|
|
}
|
|
|