From 18b7a95d999033f15a7555b893094bbc5c6c8dc9 Mon Sep 17 00:00:00 2001 From: Victor Pino Date: Mon, 23 Sep 2024 18:34:48 -0400 Subject: [PATCH] feat(src): Finnish Home Loan Process --- .../dtos/update.accept-home-loan.dto.ts | 12 ++++++ .../dtos/update.home-mounthly-details.dto.ts | 2 +- .../dtos/update.info-after-rejected.dto.ts | 12 ++++++ .../home-loan/entities/home-loan.entity.ts | 2 +- src/modules/home-loan/home-loan.controller.ts | 38 ++++++++++++++++++ src/modules/home-loan/home-loan.service.ts | 39 +++++++++++++++++++ 6 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 src/modules/home-loan/dtos/update.accept-home-loan.dto.ts create mode 100644 src/modules/home-loan/dtos/update.info-after-rejected.dto.ts diff --git a/src/modules/home-loan/dtos/update.accept-home-loan.dto.ts b/src/modules/home-loan/dtos/update.accept-home-loan.dto.ts new file mode 100644 index 0000000..2aed2a2 --- /dev/null +++ b/src/modules/home-loan/dtos/update.accept-home-loan.dto.ts @@ -0,0 +1,12 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsBoolean } from 'class-validator'; + +export class UpdateAcceptHomeLoanDto { + @ApiProperty({ + description: 'accept home loan', + example: true, + required: false, + }) + @IsBoolean() + condition: boolean; +} diff --git a/src/modules/home-loan/dtos/update.home-mounthly-details.dto.ts b/src/modules/home-loan/dtos/update.home-mounthly-details.dto.ts index f897bf1..9d12cb1 100644 --- a/src/modules/home-loan/dtos/update.home-mounthly-details.dto.ts +++ b/src/modules/home-loan/dtos/update.home-mounthly-details.dto.ts @@ -9,4 +9,4 @@ export class UpdateHomeLoanMounthlyDetailsDto { @ApiProperty() @IsString() monthlyDebt: string; -} \ No newline at end of file +} diff --git a/src/modules/home-loan/dtos/update.info-after-rejected.dto.ts b/src/modules/home-loan/dtos/update.info-after-rejected.dto.ts new file mode 100644 index 0000000..5b9c272 --- /dev/null +++ b/src/modules/home-loan/dtos/update.info-after-rejected.dto.ts @@ -0,0 +1,12 @@ +import { ApiProperty } from '@nestjs/swagger'; +import { IsNumber } from 'class-validator'; + +export class UpdateInfoAfterRejectedDto { + @ApiProperty() + @IsNumber() + priceHome: number; + + @ApiProperty() + @IsNumber() + paymentInitial: number; +} diff --git a/src/modules/home-loan/entities/home-loan.entity.ts b/src/modules/home-loan/entities/home-loan.entity.ts index 8689fef..0c0e9ec 100644 --- a/src/modules/home-loan/entities/home-loan.entity.ts +++ b/src/modules/home-loan/entities/home-loan.entity.ts @@ -42,7 +42,7 @@ export class HomeLoan { paymentInitial: string; @Column({ nullable: true }) - percentageInitial: string + percentageInitial: string; @Column({ type: 'numeric', nullable: true }) monthlyIncome: number; diff --git a/src/modules/home-loan/home-loan.controller.ts b/src/modules/home-loan/home-loan.controller.ts index f39f89d..765d7d3 100644 --- a/src/modules/home-loan/home-loan.controller.ts +++ b/src/modules/home-loan/home-loan.controller.ts @@ -27,6 +27,8 @@ import { TypeHomeDto } from './dtos/update.type-home.dto'; import { UpdateAddressHomeDto } from './dtos/update.address-home.dto'; import { UpdateHomeLoanMounthlyDetailsDto } from './dtos/update.home-mounthly-details.dto'; import { ParamsDTO } from 'src/common/dtos'; +import { UpdateAcceptHomeLoanDto } from './dtos/update.accept-home-loan.dto'; +import { UpdateInfoAfterRejectedDto } from './dtos/update.info-after-rejected.dto'; @ApiBearerAuth('JWT-auth') @ApiTags('HomeLoan') @@ -228,4 +230,40 @@ export class HomeLoanController { customer: { id: customerId }, }); } + + @Put(':id/accept-home-loan') + @ApiOperation({ summary: 'Accept home loan' }) + @ApiResponse({ + status: 200, + description: 'Accept home loan', + type: HomeLoan, + }) + @ApiResponse({ status: 404, description: 'HomeLoan not found.' }) + acceptHomeLoan( + @Param('id') id: string, + @Body() updateAcceptHomeLoanDto: UpdateAcceptHomeLoanDto, + ) { + return this.homeLoanService.updateAcceptHomeLoan( + id, + updateAcceptHomeLoanDto, + ); + } + + @Put(':id/update-info-rejected') + @ApiOperation({ summary: 'Update info after rejected' }) + @ApiResponse({ + status: 200, + description: 'the home loan updated successfully.', + type: HomeLoan, + }) + @ApiResponse({ status: 404, description: 'Home Loan not found.' }) + updateInfofterRejected( + @Param('id') id: string, + @Body() updateInfoAfterRejectedDto: UpdateInfoAfterRejectedDto, + ) { + return this.homeLoanService.updateInfoAfterRejected( + id, + updateInfoAfterRejectedDto, + ); + } } diff --git a/src/modules/home-loan/home-loan.service.ts b/src/modules/home-loan/home-loan.service.ts index f552d65..ad1572c 100644 --- a/src/modules/home-loan/home-loan.service.ts +++ b/src/modules/home-loan/home-loan.service.ts @@ -13,6 +13,8 @@ import { UpdateTermsAndConditionsDto } from './dtos/update.terms-and-conditions. import { UpdateAddressHomeDto } from './dtos/update.address-home.dto'; import { UpdateHomeLoanMounthlyDetailsDto } from './dtos/update.home-mounthly-details.dto'; import { StatusHomeLoan } from './enums/home-loan.enum'; +import { UpdateAcceptHomeLoanDto } from './dtos/update.accept-home-loan.dto'; +import { UpdateInfoAfterRejectedDto } from './dtos/update.info-after-rejected.dto'; @Injectable() export class HomeLoanService extends CrudService { @@ -142,6 +144,43 @@ export class HomeLoanService extends CrudService { homeLoan.tc = updateTermsAndConditionsDto.tc; homeLoan.status = StatusHomeLoan.CREATED; + if (Number(homeLoan.priceHome) === 125000) { + homeLoan.status = StatusHomeLoan.FAILED; + } + + return this.homeLoanRepository.save(homeLoan); + } + + async updateAcceptHomeLoan( + id: string, + updateAcceptHomeLoan: UpdateAcceptHomeLoanDto, + ): Promise { + const homeLoan = await this.findHomeLoanById(id); + + homeLoan.status = updateAcceptHomeLoan.condition + ? StatusHomeLoan.IN_PROCESS + : StatusHomeLoan.FAILED; + + return this.homeLoanRepository.save(homeLoan); + } + + async updateInfoAfterRejected( + id: string, + updateInfoAfterRejected: UpdateInfoAfterRejectedDto, + ): Promise { + const homeLoan = await this.findHomeLoanById(id); + + homeLoan.priceHome = updateInfoAfterRejected.priceHome; + homeLoan.paymentInitial = String(updateInfoAfterRejected.paymentInitial); + homeLoan.percentageInitial = + String( + (updateInfoAfterRejected.paymentInitial / + updateInfoAfterRejected.priceHome) * + 100, + ) + '%'; + + homeLoan.status = StatusHomeLoan.CREATED; + return this.homeLoanRepository.save(homeLoan); } }