Skip to content

Commit

Permalink
feat(src) add process to manager home loans
Browse files Browse the repository at this point in the history
  • Loading branch information
Victor Pino committed Sep 6, 2024
1 parent 1cec5c8 commit f582531
Show file tree
Hide file tree
Showing 18 changed files with 508 additions and 103 deletions.
17 changes: 14 additions & 3 deletions src/common/services/crud/crud.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class CrudService<T> {
where: data,
order: data.sort as FindOptionsOrder<T>,
select: this.mapSelectFields(fieldSelected as any) ?? undefined,
relations
relations,
};

const cleanedOptions = this.cleanOptions(options);
Expand Down Expand Up @@ -176,11 +176,22 @@ export class CrudService<T> {

cleanOptions<T>(obj: T): T {
const cleanedObject = Object.entries(obj).reduce((acc, [key, value]) => {
if (value === undefined || value === '' || (typeof value === 'object' && value !== null && !Array.isArray(value) && Object.keys(value).length === 0)) {
if (
value === undefined ||
value === '' ||
(typeof value === 'object' &&
value !== null &&
!Array.isArray(value) &&
Object.keys(value).length === 0)
) {
return acc;
}

if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
if (
typeof value === 'object' &&
value !== null &&
!Array.isArray(value)
) {
acc[key] = this.cleanOptions(value);
} else {
acc[key] = value;
Expand Down
4 changes: 4 additions & 0 deletions src/modules/customer/entities/customer.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from 'typeorm';
import * as bcrypt from 'bcrypt';
import { PersonalLoan } from 'src/modules/personal-loan/entities/personal-loan.entity';
import { HomeLoan } from 'src/modules/home-loan/entities/home-loan.entity';

@Entity()
export class Customer {
Expand Down Expand Up @@ -62,4 +63,7 @@ export class Customer {

@OneToMany(() => PersonalLoan, (personalLoan) => personalLoan.customer)
personalLoans: PersonalLoan[];

@OneToMany(() => HomeLoan, (homeLoan) => homeLoan.customer)
homeLoans: HomeLoan[];
}
59 changes: 50 additions & 9 deletions src/modules/home-loan/dtos/create.home-loan.dto.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,56 @@
import { ApiProperty } from '@nestjs/swagger';
import {
IsNotEmpty,
IsBoolean,
IsString,
IsNumber,
IsDate,
ArrayNotEmpty,
} from 'class-validator';
import { IsBoolean, IsString, IsNumber, ArrayNotEmpty } from 'class-validator';

export class CreateHomeLoanDto {
@ApiProperty()
@IsString()
partnerUuid: string;
propertyUsage: string;

@ApiProperty()
@IsString()
typeHouse: string;

@ApiProperty()
@IsString()
address: string;

@ApiProperty()
@IsString()
state: string;

@ApiProperty()
@IsString()
city: string;

@ApiProperty()
@IsString()
town: string;

@ApiProperty()
@IsNumber()
priceHome: number;

@ApiProperty()
@IsString()
paymentInitial: string;

@ApiProperty()
@IsNumber()
monthlyIncome: number;

@ApiProperty()
@IsNumber()
monthlyDebt: number;

@ApiProperty()
@ArrayNotEmpty()
assets: string[];

@ApiProperty()
@IsNumber()
assetsAmount: number;

@ApiProperty()
@IsBoolean()
tc: boolean;
}
20 changes: 20 additions & 0 deletions src/modules/home-loan/dtos/update.address-home.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';

export class UpdateAddressHomeDto {
@ApiProperty()
@IsString()
address: string;

@ApiProperty()
@IsString()
state: string;

@ApiProperty()
@IsString()
city: string;

@ApiProperty()
@IsString()
town: string;
}
4 changes: 4 additions & 0 deletions src/modules/home-loan/dtos/update.assets.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { PartialType } from '@nestjs/swagger';
import { UpdateAssetsDto } from 'src/modules/personal-loan/dtos/update.assets.dto';

export class UpdateHomeAssetsDto extends PartialType(UpdateAssetsDto) {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { PartialType } from '@nestjs/swagger';
import { LoanDetailsMounthlyDto } from 'src/modules/personal-loan/dtos/loan-details-mounthly.dto';

export class UpdateHomeLoanMounthlyDetailsDto extends PartialType(
LoanDetailsMounthlyDto,
) {}
8 changes: 8 additions & 0 deletions src/modules/home-loan/dtos/update.payment-initial.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNumber } from 'class-validator';

export class UpdatePaymentInitialDto {
@ApiProperty()
@IsNumber()
paymentInitial: string;
}
8 changes: 8 additions & 0 deletions src/modules/home-loan/dtos/update.price-home.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsNumber } from 'class-validator';

export class UpdatePriceHomeDto {
@ApiProperty()
@IsNumber()
priceHome: number;
}
8 changes: 8 additions & 0 deletions src/modules/home-loan/dtos/update.property-usage.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';

export class PropertyUsageDto {
@ApiProperty()
@IsString()
propertyUsage: string;
}
12 changes: 12 additions & 0 deletions src/modules/home-loan/dtos/update.terms-and-conditions.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 UpdateTermsAndConditionsDto {
@ApiProperty({
description: 'Indicates whether the terms and conditions are accepted',
example: true,
required: false,
})
@IsBoolean()
tc: boolean;
}
8 changes: 8 additions & 0 deletions src/modules/home-loan/dtos/update.type-home.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ApiProperty } from '@nestjs/swagger';
import { IsString } from 'class-validator';

export class TypeHomeDto {
@ApiProperty()
@IsString()
typeHome: string;
}
52 changes: 51 additions & 1 deletion src/modules/home-loan/entities/home-loan.entity.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,68 @@
import { Customer } from 'src/modules/customer/entities/customer.entity';
import {
Entity,
PrimaryGeneratedColumn,
Column,
CreateDateColumn,
UpdateDateColumn,
ManyToOne,
} from 'typeorm';
import { StatusHomeLoan } from '../enums/home-loan.enum';

@Entity()
export class HomeLoan {
@PrimaryGeneratedColumn('uuid')
id: string;

@ManyToOne(() => Customer, (customer) => customer.homeLoans)
customer: Customer;

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

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

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

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

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

@Column({ nullable: true })
partnerUuid: string;
town: string;

@Column({ type: 'numeric', nullable: true })
priceHome: number;

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

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

@Column({ type: 'numeric', nullable: true })
monthlyDebt: number;

@Column('text', { array: true, nullable: true })
assets: string[];

@Column({ type: 'numeric', nullable: true })
assetsAmount: number;

@Column({ type: 'boolean', nullable: true })
tc: boolean;

@Column({
type: 'enum',
enum: StatusHomeLoan,
default: StatusHomeLoan.PROPERTY_USAGE,
nullable: true,
})
status: StatusHomeLoan;

@Column({ type: 'boolean', default: true, nullable: true })
isActive: boolean;
Expand Down
15 changes: 15 additions & 0 deletions src/modules/home-loan/enums/home-loan.enum.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export enum StatusHomeLoan {
PROPERTY_USAGE = 'PROPERTY_USAGE',
TYPE_HOME = 'TYPE_HOME',
ADDRESS = 'ADDRESS',
PRICE = 'PRICE',
PAYMENT_INITIAL = 'PAYMENT_INITIAL',
MOUNTLY_FINANCE = 'MOUNTLY_FINANCE',
ASSETS = 'ASSETS',
TC = 'TC',
CREATED = 'CREATED',
PENDING = 'PENDING',
IN_PROCESS = 'IN_PROCESS',
FAILED = 'FAILED',
COMPLETED = 'COMPLETED',
}
Loading

0 comments on commit f582531

Please sign in to comment.