Skip to content

Commit

Permalink
feat(src): Add process to update status when update individual inform…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
Victor Pino committed Aug 28, 2024
1 parent e161bff commit 1ef3ec9
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 24 deletions.
22 changes: 13 additions & 9 deletions src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ export class AuthService {
private jwtService: JwtService,
) {}

async validateCustomer(email: string, password: string): Promise<LoginResponse> {
async validateCustomer(
email: string,
password: string,
): Promise<LoginResponse> {
const response: ResponseDTO<Customer> = await this.customerService.findOne({
email,
});
Expand All @@ -31,19 +34,20 @@ export class AuthService {

const customer = response.data;

const individualCustomer: ResponseDTO<IndividualCustomer> = await this.individualCustomerService.findOne(
{ customerId: { id: customer.id } }
);
const individualCustomer: ResponseDTO<IndividualCustomer> =
await this.individualCustomerService.findOne({
customerId: { id: customer.id },
});

const individual = individualCustomer.data
const individual = individualCustomer.data;

const comparePass = await bcrypt.compare(password, customer.password);

if (!comparePass) {
throw new UnauthorizedException(MESSAGES.INVALID_CREDENTIALS_ERROR);
}

return {customer, individual};
return { customer, individual };
}

async login(data: AuthValidation): Promise<ResponseDTO> {
Expand All @@ -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,
},
};
}
Expand Down
10 changes: 5 additions & 5 deletions src/modules/auth/interfaces/LoginResponse.ts
Original file line number Diff line number Diff line change
@@ -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
}
customer: Customer;
individual: IndividualCustomer;
}
2 changes: 0 additions & 2 deletions src/modules/customer/customer.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ export class CustomerController {
}
}


@Put(':id/load-names')
@ApiOperation({ summary: 'Load Names for an individual customer' })
@ApiResponse({
Expand All @@ -141,5 +140,4 @@ export class CustomerController {
const data = await this.customerService.updateLoadNames(id, loadNamesDTO);
return { data };
}

}
14 changes: 8 additions & 6 deletions src/modules/customer/customer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,14 +315,16 @@ export class CustomerService extends CrudService<Customer> {
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;
}
Expand Down
7 changes: 6 additions & 1 deletion src/modules/individual-customer/dtos/company-info.dto.ts
Original file line number Diff line number Diff line change
@@ -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({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ export enum StatusOnboarding {
EDUCATION = 'EDUCATION',
OCCUPATION = 'OCCUPATION',
COMPANY = 'COMPANY',
CONTACT = 'CONTACT'
CONTACT = 'CONTACT',
COMPLETE = 'COMPLETE'
}
15 changes: 15 additions & 0 deletions src/modules/individual-customer/individual-customer.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<IndividualCustomer> {
Expand Down Expand Up @@ -40,6 +41,8 @@ export class IndividualCustomerService extends CrudService<IndividualCustomer> {
individualCustomer.country = identityDocumentDTO.country;
individualCustomer.typeDocument = identityDocumentDTO.typeDocument;
individualCustomer.dni = identityDocumentDTO.dni;
individualCustomer.status = StatusOnboarding.ADDRESS;

return this.individualCustomerRepository.save(individualCustomer);
}

Expand All @@ -52,6 +55,8 @@ export class IndividualCustomerService extends CrudService<IndividualCustomer> {
individualCustomer.state = addressDTO.state;
individualCustomer.city = addressDTO.city;
individualCustomer.town = addressDTO.town;
individualCustomer.status = StatusOnboarding.HOUSING;

return this.individualCustomerRepository.save(individualCustomer);
}

Expand All @@ -63,6 +68,8 @@ export class IndividualCustomerService extends CrudService<IndividualCustomer> {
individualCustomer.housingType = housingDataDTO.type;
individualCustomer.housingYear = housingDataDTO.year;
individualCustomer.housingMonth = housingDataDTO.month;
individualCustomer.status = StatusOnboarding.EDUCATION;

return this.individualCustomerRepository.save(individualCustomer);
}

Expand All @@ -74,6 +81,8 @@ export class IndividualCustomerService extends CrudService<IndividualCustomer> {
individualCustomer.educationLevel = educationDataDTO.level;
individualCustomer.educationArea = educationDataDTO.area;
individualCustomer.educationYear = educationDataDTO.year;
individualCustomer.status = StatusOnboarding.OCCUPATION;

return this.individualCustomerRepository.save(individualCustomer);
}

Expand All @@ -84,6 +93,8 @@ export class IndividualCustomerService extends CrudService<IndividualCustomer> {
const individualCustomer = await this.findCustomerById(id);
individualCustomer.occupation = occupationDTO.occupation;
individualCustomer.typeBusiness = occupationDTO.typeBusiness;
individualCustomer.status = StatusOnboarding.COMPANY;

return this.individualCustomerRepository.save(individualCustomer);
}

Expand All @@ -99,6 +110,8 @@ export class IndividualCustomerService extends CrudService<IndividualCustomer> {
individualCustomer.companyCity = companyInfoDTO.city;
individualCustomer.companyYear = companyInfoDTO.year;
individualCustomer.companyMonth = companyInfoDTO.month;
individualCustomer.status = StatusOnboarding.CONTACT;

return this.individualCustomerRepository.save(individualCustomer);
}

Expand All @@ -108,6 +121,8 @@ export class IndividualCustomerService extends CrudService<IndividualCustomer> {
): Promise<IndividualCustomer> {
const individualCustomer = await this.findCustomerById(id);
individualCustomer.phone = contactInfoDTO.phone;
individualCustomer.status = StatusOnboarding.COMPLETE;

return this.individualCustomerRepository.save(individualCustomer);
}
}

0 comments on commit 1ef3ec9

Please sign in to comment.