Skip to content

Commit

Permalink
feat(src): Finnish Home Loan Process
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Pino committed Sep 23, 2024
1 parent 3f30cff commit 18b7a95
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/modules/home-loan/dtos/update.accept-home-loan.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export class UpdateHomeLoanMounthlyDetailsDto {
@ApiProperty()
@IsString()
monthlyDebt: string;
}
}
12 changes: 12 additions & 0 deletions src/modules/home-loan/dtos/update.info-after-rejected.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
2 changes: 1 addition & 1 deletion src/modules/home-loan/entities/home-loan.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class HomeLoan {
paymentInitial: string;

@Column({ nullable: true })
percentageInitial: string
percentageInitial: string;

@Column({ type: 'numeric', nullable: true })
monthlyIncome: number;
Expand Down
38 changes: 38 additions & 0 deletions src/modules/home-loan/home-loan.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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,
);
}
}
39 changes: 39 additions & 0 deletions src/modules/home-loan/home-loan.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<HomeLoan> {
Expand Down Expand Up @@ -142,6 +144,43 @@ export class HomeLoanService extends CrudService<HomeLoan> {
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<HomeLoan> {
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<HomeLoan> {
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);
}
}

0 comments on commit 18b7a95

Please sign in to comment.