UPDATE: Added log-lib on more routes and services

This commit is contained in:
rodrigo.zamboni
2022-06-29 14:12:13 -03:00
parent bc0d456c2a
commit a39622bfa1
11 changed files with 222 additions and 132 deletions
+20 -17
View File
@@ -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;