From 60520cc1d0c66278e747e9b1fb572eff99981474 Mon Sep 17 00:00:00 2001 From: Raphael Rivas Date: Tue, 16 Jan 2024 18:41:03 -0300 Subject: [PATCH] feat: remove CoreBank mock in auth, cronjobs --- src/auth/auth.controller.ts | 22 +++++++++++----------- src/auth/auth.module.ts | 4 ---- src/auth/auth.service.spec.ts | 8 -------- src/auth/auth.service.ts | 11 ----------- src/cron-jobs/cron-jobs.service.ts | 17 ----------------- 5 files changed, 11 insertions(+), 51 deletions(-) diff --git a/src/auth/auth.controller.ts b/src/auth/auth.controller.ts index 3a38b36c..dbd7f16e 100644 --- a/src/auth/auth.controller.ts +++ b/src/auth/auth.controller.ts @@ -39,7 +39,7 @@ export class AuthController { private logger: Logger = new Logger('AuthController', { timestamp: true }); constructor( - private readonly service: AuthService, + private readonly authService: AuthService, private readonly mailHistoryService: MailHistoryService, ) {} @@ -51,7 +51,7 @@ export class AuthController { public login( @Body() loginDto: AuthEmailLoginDto, ): Promise { - return this.service.validateLogin(loginDto, false); + return this.authService.validateLogin(loginDto, false); } @SerializeOptions({ @@ -62,7 +62,7 @@ export class AuthController { public adminLogin( @Body() loginDTO: AuthEmailLoginDto, ): Promise { - return this.service.validateLogin(loginDTO, true); + return this.authService.validateLogin(loginDTO, true); } @Post('email/register') @@ -70,7 +70,7 @@ export class AuthController { async register( @Body() createUserDto: AuthRegisterLoginDto, ): Promise { - return await this.service.register(createUserDto); + return await this.authService.register(createUserDto); } @Post('email/confirm') @@ -78,7 +78,7 @@ export class AuthController { async confirmEmail( @Body() confirmEmailDto: AuthConfirmEmailDto, ): Promise { - return this.service.confirmEmail(confirmEmailDto.hash); + return this.authService.confirmEmail(confirmEmailDto.hash); } @ApiBearerAuth() @@ -92,7 +92,7 @@ export class AuthController { async resendRegisterMail( @Body() resendEmailDto: AuthResendEmailDto, ): Promise { - return this.service.resendRegisterMail(resendEmailDto); + return this.authService.resendRegisterMail(resendEmailDto); } @Post('forgot/password') @@ -100,13 +100,13 @@ export class AuthController { async forgotPassword( @Body() forgotPasswordDto: AuthForgotPasswordDto, ): Promise { - return this.service.forgotPassword(forgotPasswordDto.email); + return this.authService.forgotPassword(forgotPasswordDto.email); } @Post('reset/password') @HttpCode(HttpStatus.NO_CONTENT) resetPassword(@Body() resetPasswordDto: AuthResetPasswordDto): Promise { - return this.service.resetPassword( + return this.authService.resetPassword( resetPasswordDto.hash, resetPasswordDto.password, ); @@ -120,7 +120,7 @@ export class AuthController { @UseGuards(AuthGuard('jwt')) @HttpCode(HttpStatus.OK) public me(@Request() request): Promise> { - return this.service.me(request.user); + return this.authService.me(request.user); } @ApiBearerAuth() @@ -134,7 +134,7 @@ export class AuthController { @Request() request, @Body() userDto: AuthUpdateDto, ): Promise> { - return this.service.update(request.user, userDto); + return this.authService.update(request.user, userDto); } @ApiBearerAuth() @@ -142,6 +142,6 @@ export class AuthController { @UseGuards(AuthGuard('jwt')) @HttpCode(HttpStatus.NO_CONTENT) public async delete(@Request() request): Promise { - return this.service.softDelete(request.user); + return this.authService.softDelete(request.user); } } diff --git a/src/auth/auth.module.ts b/src/auth/auth.module.ts index ffe0d689..dbcdcb43 100644 --- a/src/auth/auth.module.ts +++ b/src/auth/auth.module.ts @@ -11,9 +11,7 @@ import { ForgotModule } from 'src/forgot/forgot.module'; import { MailModule } from 'src/mail/mail.module'; import { IsExist } from 'src/utils/validators/is-exists.validator'; import { IsNotExist } from 'src/utils/validators/is-not-exists.validator'; -import { CoreBankService } from 'src/core-bank/core-bank.service'; import { IsValidBankCodeConstraint } from 'src/banks/validators/is-valid-bank-code.validator'; -import { CoreBankModule } from 'src/core-bank/core-bank.module'; import { MailHistoryModule } from 'src/mail-history/mail-history.module'; @Module({ @@ -22,7 +20,6 @@ import { MailHistoryModule } from 'src/mail-history/mail-history.module'; ForgotModule, PassportModule, MailModule, - CoreBankModule, MailHistoryModule, JwtModule.registerAsync({ imports: [ConfigModule], @@ -42,7 +39,6 @@ import { MailHistoryModule } from 'src/mail-history/mail-history.module'; AuthService, JwtStrategy, AnonymousStrategy, - CoreBankService, IsValidBankCodeConstraint, ], exports: [AuthService], diff --git a/src/auth/auth.service.spec.ts b/src/auth/auth.service.spec.ts index d6c9dad6..f00220cf 100644 --- a/src/auth/auth.service.spec.ts +++ b/src/auth/auth.service.spec.ts @@ -1,7 +1,6 @@ import { Provider } from '@nestjs/common'; import { JwtService } from '@nestjs/jwt'; import { Test, TestingModule } from '@nestjs/testing'; -import { CoreBankService } from 'src/core-bank/core-bank.service'; import { ForgotService } from 'src/forgot/forgot.service'; import { InviteStatusEnum } from 'src/mail-history-statuses/mail-history-status.enum'; import { MailHistory } from 'src/mail-history/entities/mail-history.entity'; @@ -54,12 +53,6 @@ describe('AuthService', () => { sendForgotPassword: jest.fn(), }, } as Provider; - const coreBankServiceMock = { - provide: CoreBankService, - useValue: { - updateDataIfNeeded: jest.fn(), - }, - } as Provider; const mailHistoryServiceMock = { provide: MailHistoryService, useValue: { @@ -83,7 +76,6 @@ describe('AuthService', () => { usersServiceMock, forgotServiceMock, mailServiceMock, - coreBankServiceMock, mailHistoryServiceMock, ], }).compile(); diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 0a6c3a3d..154a3dba 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -4,8 +4,6 @@ import { JwtService } from '@nestjs/jwt'; import * as bcrypt from 'bcryptjs'; import { plainToClass } from 'class-transformer'; import * as crypto from 'crypto'; -import { CoreBankService } from 'src/core-bank/core-bank.service'; -import { UpdateCoreBankInterface } from 'src/core-bank/interfaces/update-core-bank.interface'; import { ForgotService } from 'src/forgot/forgot.service'; import { InviteStatusEnum } from 'src/mail-history-statuses/mail-history-status.enum'; import { MailHistory } from 'src/mail-history/entities/mail-history.entity'; @@ -38,7 +36,6 @@ export class AuthService { private usersService: UsersService, private forgotService: ForgotService, private mailService: MailService, - private coreBankService: CoreBankService, private mailHistoryService: MailHistoryService, ) {} @@ -491,14 +488,6 @@ export class AuthService { 'AuthService.update()', ); - const coreBankProfile: UpdateCoreBankInterface = { - bankAccountCode: userProfile.bankAccount, - bankAccountDigit: userProfile.bankAccountDigit, - bankAgencyCode: userProfile.bankAgency, - bankCode: userProfile.bankCode, - }; - this.coreBankService.update(userProfile.cpfCnpj, coreBankProfile); - return userProfile; } diff --git a/src/cron-jobs/cron-jobs.service.ts b/src/cron-jobs/cron-jobs.service.ts index bc0a540b..88d1b182 100644 --- a/src/cron-jobs/cron-jobs.service.ts +++ b/src/cron-jobs/cron-jobs.service.ts @@ -2,7 +2,6 @@ import { HttpStatus, Injectable, Logger, OnModuleInit } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { CronExpression, SchedulerRegistry } from '@nestjs/schedule'; import { CronJob, CronJobParameters } from 'cron'; -import { CoreBankService } from 'src/core-bank/core-bank.service'; import { JaeService } from 'src/jae/jae.service'; import { InviteStatusEnum } from 'src/mail-history-statuses/mail-history-status.enum'; import { MailHistory } from 'src/mail-history/entities/mail-history.entity'; @@ -25,7 +24,6 @@ import { validateEmail } from 'validations-br'; export enum CrobJobsEnum { bulkSendInvites = 'bulkSendInvites', updateJaeMockedData = 'updateJaeMockedData', - updateCoreBankMockedData = 'updateCoreBankMockedData', sendStatusReport = 'sendStatusReport', pollDb = 'pollDb', } @@ -54,7 +52,6 @@ export class CronJobsService implements OnModuleInit { private mailService: MailService, private mailHistoryService: MailHistoryService, private jaeService: JaeService, - private coreBankService: CoreBankService, private usersService: UsersService, ) {} @@ -69,13 +66,6 @@ export class CronJobsService implements OnModuleInit { onTick: async () => this.updateJaeMockedData(), }, }, - { - name: CrobJobsEnum.updateCoreBankMockedData, - cronJobParameters: { - cronTime: CronExpression.EVERY_HOUR, - onTick: () => this.coreBankService.updateDataIfNeeded(), - }, - }, { name: CrobJobsEnum.bulkSendInvites, cronJobParameters: { @@ -143,13 +133,6 @@ export class CronJobsService implements OnModuleInit { await this.jaeService.updateDataIfNeeded(); } - updateCoreBankMockedData() { - this.logger.log( - `updateCoreBankMockedData(): Atualizando dados se necessário`, - ); - this.coreBankService.updateDataIfNeeded(); - } - async bulkSendInvites() { const THIS_METHOD = `${this.bulkSendInvites.name}()`; const THIS_CLASS_AND_METHOD = `${CronJobsService}.${this.bulkSendInvites.name}()`;