From 1ef3ec9ee4947af5d10ad2e1c5f81c2842ab4bbc Mon Sep 17 00:00:00 2001 From: Victor Pino Date: Tue, 27 Aug 2024 22:56:32 -0400 Subject: [PATCH] feat(src): Add process to update status when update individual information --- src/modules/auth/auth.service.ts | 22 +++++++++++-------- src/modules/auth/interfaces/LoginResponse.ts | 10 ++++----- src/modules/customer/customer.controller.ts | 2 -- src/modules/customer/customer.service.ts | 14 +++++++----- .../dtos/company-info.dto.ts | 7 +++++- .../enums/individual-customer.enum.ts | 3 ++- .../individual-customer.service.ts | 15 +++++++++++++ 7 files changed, 49 insertions(+), 24 deletions(-) diff --git a/src/modules/auth/auth.service.ts b/src/modules/auth/auth.service.ts index 6775c9c..3e18354 100644 --- a/src/modules/auth/auth.service.ts +++ b/src/modules/auth/auth.service.ts @@ -20,7 +20,10 @@ export class AuthService { private jwtService: JwtService, ) {} - async validateCustomer(email: string, password: string): Promise { + async validateCustomer( + email: string, + password: string, + ): Promise { const response: ResponseDTO = await this.customerService.findOne({ email, }); @@ -31,11 +34,12 @@ export class AuthService { const customer = response.data; - const individualCustomer: ResponseDTO = await this.individualCustomerService.findOne( - { customerId: { id: customer.id } } - ); + const individualCustomer: ResponseDTO = + await this.individualCustomerService.findOne({ + customerId: { id: customer.id }, + }); - const individual = individualCustomer.data + const individual = individualCustomer.data; const comparePass = await bcrypt.compare(password, customer.password); @@ -43,7 +47,7 @@ export class AuthService { throw new UnauthorizedException(MESSAGES.INVALID_CREDENTIALS_ERROR); } - return {customer, individual}; + return { customer, individual }; } async login(data: AuthValidation): Promise { @@ -58,10 +62,10 @@ export class AuthService { return { data: { - status: response.customer.isActive, + status: response?.customer?.isActive, access_token: accessToken, - individual: response.individual, - id: response.customer.id + individual: response?.individual, + id: response?.customer?.id, }, }; } diff --git a/src/modules/auth/interfaces/LoginResponse.ts b/src/modules/auth/interfaces/LoginResponse.ts index d8c67c8..1e4bf19 100644 --- a/src/modules/auth/interfaces/LoginResponse.ts +++ b/src/modules/auth/interfaces/LoginResponse.ts @@ -1,7 +1,7 @@ -import { Customer } from "src/modules/customer/entities/customer.entity"; -import { IndividualCustomer } from "src/modules/individual-customer/entities/individual-customer.entity"; +import { Customer } from 'src/modules/customer/entities/customer.entity'; +import { IndividualCustomer } from 'src/modules/individual-customer/entities/individual-customer.entity'; export interface LoginResponse { - customer: Customer, - individual: IndividualCustomer -} \ No newline at end of file + customer: Customer; + individual: IndividualCustomer; +} diff --git a/src/modules/customer/customer.controller.ts b/src/modules/customer/customer.controller.ts index 0540c00..4d17191 100644 --- a/src/modules/customer/customer.controller.ts +++ b/src/modules/customer/customer.controller.ts @@ -127,7 +127,6 @@ export class CustomerController { } } - @Put(':id/load-names') @ApiOperation({ summary: 'Load Names for an individual customer' }) @ApiResponse({ @@ -141,5 +140,4 @@ export class CustomerController { const data = await this.customerService.updateLoadNames(id, loadNamesDTO); return { data }; } - } diff --git a/src/modules/customer/customer.service.ts b/src/modules/customer/customer.service.ts index 448e932..23fe8f7 100644 --- a/src/modules/customer/customer.service.ts +++ b/src/modules/customer/customer.service.ts @@ -315,14 +315,16 @@ export class CustomerService extends CrudService { throw new NotFoundException(`Customer with ID ${customerId} not found`); } - let individualCustomer = await this.individualCustomerService.findOne( - { customerId: { id: customerId } }, - ); + let individualCustomer = await this.individualCustomerService.findOne({ + customerId: { id: customerId }, + }); if (!individualCustomer.data) { - const newIndividualCustomer = await this.individualCustomerService.create({ - customerId: customer, - }); + const newIndividualCustomer = await this.individualCustomerService.create( + { + customerId: customer, + }, + ); individualCustomer.data = newIndividualCustomer; } diff --git a/src/modules/individual-customer/dtos/company-info.dto.ts b/src/modules/individual-customer/dtos/company-info.dto.ts index 55b23b5..10256c7 100644 --- a/src/modules/individual-customer/dtos/company-info.dto.ts +++ b/src/modules/individual-customer/dtos/company-info.dto.ts @@ -1,5 +1,10 @@ import { ApiProperty } from '@nestjs/swagger'; -import { IsString, Length, IsPhoneNumber, IsNumberString } from 'class-validator'; +import { + IsString, + Length, + IsPhoneNumber, + IsNumberString, +} from 'class-validator'; export class CompanyInfoDTO { @ApiProperty({ diff --git a/src/modules/individual-customer/enums/individual-customer.enum.ts b/src/modules/individual-customer/enums/individual-customer.enum.ts index ca5097b..67b440f 100644 --- a/src/modules/individual-customer/enums/individual-customer.enum.ts +++ b/src/modules/individual-customer/enums/individual-customer.enum.ts @@ -6,5 +6,6 @@ export enum StatusOnboarding { EDUCATION = 'EDUCATION', OCCUPATION = 'OCCUPATION', COMPANY = 'COMPANY', - CONTACT = 'CONTACT' + CONTACT = 'CONTACT', + COMPLETE = 'COMPLETE' } diff --git a/src/modules/individual-customer/individual-customer.service.ts b/src/modules/individual-customer/individual-customer.service.ts index 5c62cc2..2403816 100644 --- a/src/modules/individual-customer/individual-customer.service.ts +++ b/src/modules/individual-customer/individual-customer.service.ts @@ -10,6 +10,7 @@ import { EducationDataDTO } from './dtos/education-data.dto'; import { HousingDataDTO } from './dtos/housing-data.dto'; import { IdentityDocumentDTO } from './dtos/identity-document.dto'; import { OccupationDTO } from './dtos/occupation.dto'; +import { StatusOnboarding } from './enums/individual-customer.enum'; @Injectable() export class IndividualCustomerService extends CrudService { @@ -40,6 +41,8 @@ export class IndividualCustomerService extends CrudService { individualCustomer.country = identityDocumentDTO.country; individualCustomer.typeDocument = identityDocumentDTO.typeDocument; individualCustomer.dni = identityDocumentDTO.dni; + individualCustomer.status = StatusOnboarding.ADDRESS; + return this.individualCustomerRepository.save(individualCustomer); } @@ -52,6 +55,8 @@ export class IndividualCustomerService extends CrudService { individualCustomer.state = addressDTO.state; individualCustomer.city = addressDTO.city; individualCustomer.town = addressDTO.town; + individualCustomer.status = StatusOnboarding.HOUSING; + return this.individualCustomerRepository.save(individualCustomer); } @@ -63,6 +68,8 @@ export class IndividualCustomerService extends CrudService { individualCustomer.housingType = housingDataDTO.type; individualCustomer.housingYear = housingDataDTO.year; individualCustomer.housingMonth = housingDataDTO.month; + individualCustomer.status = StatusOnboarding.EDUCATION; + return this.individualCustomerRepository.save(individualCustomer); } @@ -74,6 +81,8 @@ export class IndividualCustomerService extends CrudService { individualCustomer.educationLevel = educationDataDTO.level; individualCustomer.educationArea = educationDataDTO.area; individualCustomer.educationYear = educationDataDTO.year; + individualCustomer.status = StatusOnboarding.OCCUPATION; + return this.individualCustomerRepository.save(individualCustomer); } @@ -84,6 +93,8 @@ export class IndividualCustomerService extends CrudService { const individualCustomer = await this.findCustomerById(id); individualCustomer.occupation = occupationDTO.occupation; individualCustomer.typeBusiness = occupationDTO.typeBusiness; + individualCustomer.status = StatusOnboarding.COMPANY; + return this.individualCustomerRepository.save(individualCustomer); } @@ -99,6 +110,8 @@ export class IndividualCustomerService extends CrudService { individualCustomer.companyCity = companyInfoDTO.city; individualCustomer.companyYear = companyInfoDTO.year; individualCustomer.companyMonth = companyInfoDTO.month; + individualCustomer.status = StatusOnboarding.CONTACT; + return this.individualCustomerRepository.save(individualCustomer); } @@ -108,6 +121,8 @@ export class IndividualCustomerService extends CrudService { ): Promise { const individualCustomer = await this.findCustomerById(id); individualCustomer.phone = contactInfoDTO.phone; + individualCustomer.status = StatusOnboarding.COMPLETE; + return this.individualCustomerRepository.save(individualCustomer); } }