Skip to content

Commit 18b7a95

Browse files
committed
feat(src): Finnish Home Loan Process
1 parent 3f30cff commit 18b7a95

File tree

6 files changed

+103
-2
lines changed

6 files changed

+103
-2
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsBoolean } from 'class-validator';
3+
4+
export class UpdateAcceptHomeLoanDto {
5+
@ApiProperty({
6+
description: 'accept home loan',
7+
example: true,
8+
required: false,
9+
})
10+
@IsBoolean()
11+
condition: boolean;
12+
}

src/modules/home-loan/dtos/update.home-mounthly-details.dto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ export class UpdateHomeLoanMounthlyDetailsDto {
99
@ApiProperty()
1010
@IsString()
1111
monthlyDebt: string;
12-
}
12+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { ApiProperty } from '@nestjs/swagger';
2+
import { IsNumber } from 'class-validator';
3+
4+
export class UpdateInfoAfterRejectedDto {
5+
@ApiProperty()
6+
@IsNumber()
7+
priceHome: number;
8+
9+
@ApiProperty()
10+
@IsNumber()
11+
paymentInitial: number;
12+
}

src/modules/home-loan/entities/home-loan.entity.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ export class HomeLoan {
4242
paymentInitial: string;
4343

4444
@Column({ nullable: true })
45-
percentageInitial: string
45+
percentageInitial: string;
4646

4747
@Column({ type: 'numeric', nullable: true })
4848
monthlyIncome: number;

src/modules/home-loan/home-loan.controller.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import { TypeHomeDto } from './dtos/update.type-home.dto';
2727
import { UpdateAddressHomeDto } from './dtos/update.address-home.dto';
2828
import { UpdateHomeLoanMounthlyDetailsDto } from './dtos/update.home-mounthly-details.dto';
2929
import { ParamsDTO } from 'src/common/dtos';
30+
import { UpdateAcceptHomeLoanDto } from './dtos/update.accept-home-loan.dto';
31+
import { UpdateInfoAfterRejectedDto } from './dtos/update.info-after-rejected.dto';
3032

3133
@ApiBearerAuth('JWT-auth')
3234
@ApiTags('HomeLoan')
@@ -228,4 +230,40 @@ export class HomeLoanController {
228230
customer: { id: customerId },
229231
});
230232
}
233+
234+
@Put(':id/accept-home-loan')
235+
@ApiOperation({ summary: 'Accept home loan' })
236+
@ApiResponse({
237+
status: 200,
238+
description: 'Accept home loan',
239+
type: HomeLoan,
240+
})
241+
@ApiResponse({ status: 404, description: 'HomeLoan not found.' })
242+
acceptHomeLoan(
243+
@Param('id') id: string,
244+
@Body() updateAcceptHomeLoanDto: UpdateAcceptHomeLoanDto,
245+
) {
246+
return this.homeLoanService.updateAcceptHomeLoan(
247+
id,
248+
updateAcceptHomeLoanDto,
249+
);
250+
}
251+
252+
@Put(':id/update-info-rejected')
253+
@ApiOperation({ summary: 'Update info after rejected' })
254+
@ApiResponse({
255+
status: 200,
256+
description: 'the home loan updated successfully.',
257+
type: HomeLoan,
258+
})
259+
@ApiResponse({ status: 404, description: 'Home Loan not found.' })
260+
updateInfofterRejected(
261+
@Param('id') id: string,
262+
@Body() updateInfoAfterRejectedDto: UpdateInfoAfterRejectedDto,
263+
) {
264+
return this.homeLoanService.updateInfoAfterRejected(
265+
id,
266+
updateInfoAfterRejectedDto,
267+
);
268+
}
231269
}

src/modules/home-loan/home-loan.service.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import { UpdateTermsAndConditionsDto } from './dtos/update.terms-and-conditions.
1313
import { UpdateAddressHomeDto } from './dtos/update.address-home.dto';
1414
import { UpdateHomeLoanMounthlyDetailsDto } from './dtos/update.home-mounthly-details.dto';
1515
import { StatusHomeLoan } from './enums/home-loan.enum';
16+
import { UpdateAcceptHomeLoanDto } from './dtos/update.accept-home-loan.dto';
17+
import { UpdateInfoAfterRejectedDto } from './dtos/update.info-after-rejected.dto';
1618

1719
@Injectable()
1820
export class HomeLoanService extends CrudService<HomeLoan> {
@@ -142,6 +144,43 @@ export class HomeLoanService extends CrudService<HomeLoan> {
142144
homeLoan.tc = updateTermsAndConditionsDto.tc;
143145
homeLoan.status = StatusHomeLoan.CREATED;
144146

147+
if (Number(homeLoan.priceHome) === 125000) {
148+
homeLoan.status = StatusHomeLoan.FAILED;
149+
}
150+
151+
return this.homeLoanRepository.save(homeLoan);
152+
}
153+
154+
async updateAcceptHomeLoan(
155+
id: string,
156+
updateAcceptHomeLoan: UpdateAcceptHomeLoanDto,
157+
): Promise<HomeLoan> {
158+
const homeLoan = await this.findHomeLoanById(id);
159+
160+
homeLoan.status = updateAcceptHomeLoan.condition
161+
? StatusHomeLoan.IN_PROCESS
162+
: StatusHomeLoan.FAILED;
163+
164+
return this.homeLoanRepository.save(homeLoan);
165+
}
166+
167+
async updateInfoAfterRejected(
168+
id: string,
169+
updateInfoAfterRejected: UpdateInfoAfterRejectedDto,
170+
): Promise<HomeLoan> {
171+
const homeLoan = await this.findHomeLoanById(id);
172+
173+
homeLoan.priceHome = updateInfoAfterRejected.priceHome;
174+
homeLoan.paymentInitial = String(updateInfoAfterRejected.paymentInitial);
175+
homeLoan.percentageInitial =
176+
String(
177+
(updateInfoAfterRejected.paymentInitial /
178+
updateInfoAfterRejected.priceHome) *
179+
100,
180+
) + '%';
181+
182+
homeLoan.status = StatusHomeLoan.CREATED;
183+
145184
return this.homeLoanRepository.save(homeLoan);
146185
}
147186
}

0 commit comments

Comments
 (0)