mirror of
https://github.com/dadosfera/maestro.git
synced 2026-10-14 13:59:08 +00:00
UPDATE: Added log-lib on more routes and services
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
Logger,
|
||||
Body,
|
||||
Controller,
|
||||
Headers,
|
||||
@@ -7,6 +6,7 @@ import {
|
||||
HttpCode,
|
||||
HttpStatus,
|
||||
OnApplicationBootstrap,
|
||||
Inject,
|
||||
} from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import {
|
||||
@@ -24,23 +24,26 @@ import {
|
||||
import { AuthClientService } from '../../clients/auth/client.service';
|
||||
import { PermissionsClientService } from '../../clients/permissions/client.service';
|
||||
import { Permissions } from '../../authentication/permissions.enum';
|
||||
|
||||
import { DadosferaLogger } from 'dadosfera-logs';
|
||||
import ErrorBuilder from '../../utils/ErrorBuilder';
|
||||
import { LoginDto } from './dtos/login';
|
||||
|
||||
@ApiTags('Auth')
|
||||
@Controller('auth')
|
||||
export class AuthController implements OnApplicationBootstrap {
|
||||
private readonly logger = new Logger(AuthController.name);
|
||||
logger: any;
|
||||
|
||||
constructor(
|
||||
@Inject(DadosferaLogger)
|
||||
dadosferaLogger: DadosferaLogger,
|
||||
private authClient: AuthClientService,
|
||||
private permissionsClient: PermissionsClientService,
|
||||
) {}
|
||||
) {
|
||||
this.logger = dadosferaLogger.logger;
|
||||
}
|
||||
|
||||
// internally used to send permissions to duc on microservice startup
|
||||
async onApplicationBootstrap() {
|
||||
this.logger.log('sending permissions to DUC...');
|
||||
this.logger.info('sending permissions to DUC...');
|
||||
|
||||
const permissions = Object.values(Permissions).flatMap((namespace) =>
|
||||
Object.values(namespace),
|
||||
@@ -53,7 +56,7 @@ export class AuthController implements OnApplicationBootstrap {
|
||||
err.code === 'No connection established' &&
|
||||
process.env.LOCAL_ENV === 'true'
|
||||
) {
|
||||
return this.logger.log(
|
||||
return this.logger.info(
|
||||
"couldn't connect to DUC. suppresing in local env",
|
||||
);
|
||||
}
|
||||
@@ -65,7 +68,7 @@ export class AuthController implements OnApplicationBootstrap {
|
||||
@Post('sign-in')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async signIn(@Body() { username, password, totp }: AuthSignInRequest) {
|
||||
this.logger.log(`/auth`, 'SignIn');
|
||||
this.logger.info('/auth - SignIn');
|
||||
|
||||
return this.authClient.signIn({ username, password, totp });
|
||||
}
|
||||
@@ -75,7 +78,7 @@ export class AuthController implements OnApplicationBootstrap {
|
||||
async refreshAccessToken(
|
||||
@Body() { refreshToken }: AuthRefreshAccessTokenRequest,
|
||||
) {
|
||||
this.logger.log(`/auth`, 'RefreshAccessToken');
|
||||
this.logger.info('/auth - RefreshAccessToken');
|
||||
|
||||
return this.authClient.refreshAccessToken({ refreshToken });
|
||||
}
|
||||
@@ -86,7 +89,7 @@ export class AuthController implements OnApplicationBootstrap {
|
||||
@Body() body: AuthChangePasswordRequest,
|
||||
@Headers() headers,
|
||||
) {
|
||||
this.logger.log(`/auth`, 'change-password');
|
||||
this.logger.info('/auth - change-password');
|
||||
|
||||
const { oldPassword, newPassword } = body;
|
||||
const { authorization: accessToken } = headers;
|
||||
@@ -101,7 +104,7 @@ export class AuthController implements OnApplicationBootstrap {
|
||||
@Post('reset-password')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async resetPassword(@Body() body: AuthResetPasswordRequest) {
|
||||
this.logger.log(`/auth`, 'reset-password');
|
||||
this.logger.info('/auth - reset-password');
|
||||
|
||||
const { username } = body;
|
||||
|
||||
@@ -113,7 +116,7 @@ export class AuthController implements OnApplicationBootstrap {
|
||||
async verifyResetPasswordCode(
|
||||
@Body() body: AuthVerifyResetPasswordCodeRequest,
|
||||
) {
|
||||
this.logger.log(`/auth`, 'verify-reset-password-code');
|
||||
this.logger.info('/auth - verify-reset-password-code');
|
||||
|
||||
const { username, code } = body;
|
||||
|
||||
@@ -123,7 +126,7 @@ export class AuthController implements OnApplicationBootstrap {
|
||||
@Post('confirm-reset-password')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async confirmResetPassword(@Body() body: AuthConfirmResetPasswordRequest) {
|
||||
this.logger.log(`/auth`, 'confirm-reset-password');
|
||||
this.logger.info('/auth - confirm-reset-password');
|
||||
|
||||
const { username, code, newPassword } = body;
|
||||
|
||||
@@ -140,7 +143,7 @@ export class AuthController implements OnApplicationBootstrap {
|
||||
@Body() body: AuthEnableTotpMfaRequest,
|
||||
@Headers() headers,
|
||||
) {
|
||||
this.logger.log(`/auth`, 'enable-totp');
|
||||
this.logger.info('/auth - enable-totp');
|
||||
|
||||
const { password } = body;
|
||||
const { authorization: accessToken } = headers;
|
||||
@@ -154,7 +157,7 @@ export class AuthController implements OnApplicationBootstrap {
|
||||
@Body() body: AuthDisableTotpMfaRequest,
|
||||
@Headers() headers,
|
||||
) {
|
||||
this.logger.log(`/auth`, 'disable-totp');
|
||||
this.logger.info('/auth - disable-totp');
|
||||
|
||||
const { password } = body;
|
||||
const { authorization: accessToken } = headers;
|
||||
@@ -165,7 +168,7 @@ export class AuthController implements OnApplicationBootstrap {
|
||||
@Post('dismiss-totp')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async dismissTotpMFA(@Headers() headers) {
|
||||
this.logger.log(`/auth`, 'disable-totp');
|
||||
this.logger.info('/auth - disable-totp');
|
||||
|
||||
const { authorization: accessToken } = headers;
|
||||
|
||||
@@ -175,7 +178,7 @@ export class AuthController implements OnApplicationBootstrap {
|
||||
@Post('verify-totp')
|
||||
@HttpCode(HttpStatus.OK)
|
||||
async verifyTotp(@Body() body: AuthVerifyTotpMfaRequest, @Headers() headers) {
|
||||
this.logger.log(`/auth`, 'enable-totp');
|
||||
this.logger.info('/auth - enable-totp');
|
||||
|
||||
const { totp } = body;
|
||||
const { authorization: accessToken } = headers;
|
||||
|
||||
Reference in New Issue
Block a user