Skip to content

Commit

Permalink
[NestJS] Milestone 5: Family and occupation risk assessment
Browse files Browse the repository at this point in the history
  • Loading branch information
javiertoledo committed May 4, 2023
1 parent 41cd187 commit 26d30f1
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 2 deletions.
2 changes: 2 additions & 0 deletions kyc-nest/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ConfigModule } from '@nestjs/config';
import { AppController } from './app.controller';
import { AppService } from './app.service';
import { ProfileModule } from './profile/profile.module';
import { RelativeModule } from './relative/relative.module';
import { TypeOrmModule } from '@nestjs/typeorm';
import { KycModule } from './kyc/kyc.module';

Expand All @@ -16,6 +17,7 @@ import { KycModule } from './kyc/kyc.module';
synchronize: true,
}),
ProfileModule,
RelativeModule,
KycModule,
],
controllers: [AppController],
Expand Down
10 changes: 9 additions & 1 deletion kyc-nest/src/profile/profile.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Controller, Get, Param, Post, Body } from '@nestjs/common';
import { Controller, Get, Param, Post, Body, Put } from '@nestjs/common';
import { ProfileService } from './profile.service';
import { Profile } from './profile.entity';

Expand All @@ -11,6 +11,14 @@ export class ProfileController {
return this.profileService.create(profileData);
}

@Put(':id')
async update(
@Param('id') id: string,
@Body() profileData: Partial<Profile>,
): Promise<void> {
return this.profileService.update(id, profileData);
}

@Get()
async findAll(): Promise<Profile[]> {
return this.profileService.findAll();
Expand Down
27 changes: 26 additions & 1 deletion kyc-nest/src/profile/profile.entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm';
import { Entity, PrimaryGeneratedColumn, Column, OneToMany } from 'typeorm';
import { Relative } from '../relative/relative.entity';

export type KYCStatus =
| 'KYCPending'
Expand All @@ -10,6 +11,18 @@ export type KYCStatus =
| 'KYCBackgroundCheckRequiresManualReview'
| 'KYCBackgroundCheckRejected';

export enum IncomeSource {
Salary = 'Salary',
Dividends = 'Dividends',
BusinessIncome = 'Business Income',
Freelance = 'Freelance',
RentalIncome = 'Rental Income',
Royalties = 'Royalties',
Investments = 'Investments',
Pensions = 'Pensions',
SocialSecurity = 'Social Security',
}

@Entity()
export class Profile {
@PrimaryGeneratedColumn()
Expand Down Expand Up @@ -54,6 +67,15 @@ export class Profile {
@Column({ nullable: true })
tin?: string;

@Column({ nullable: true })
occupation?: string;

@Column({ nullable: true })
employer?: string;

@Column({ nullable: true, type: 'varchar' })
sourceOfIncome?: IncomeSource;

@Column({ default: 'KYCPending' })
kycStatus: KYCStatus;

Expand Down Expand Up @@ -86,4 +108,7 @@ export class Profile {

@Column({ nullable: true })
backgroundCheckRejectedAt?: string;

@OneToMany(() => Relative, (relative) => relative.profile, { cascade: true })
relatives: Relative[];
}
1 change: 1 addition & 0 deletions kyc-nest/src/profile/profile.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class ProfileService {
async findById(id: string): Promise<Profile> {
const options: FindOneOptions<Profile> = {
where: { id },
relations: ['relatives'],
};

const profile = await this.profileRepository.findOne(options);
Expand Down
16 changes: 16 additions & 0 deletions kyc-nest/src/relative/relative.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Controller, Post, Body, Param } from '@nestjs/common';
import { RelativeService } from './relative.service';
import { Relative } from './relative.entity';

@Controller('profiles/:profileId/relatives')
export class RelativeController {
constructor(private readonly relativeService: RelativeService) {}

@Post()
async create(
@Param('profileId') profileId: string,
@Body() relativeData: Relative,
): Promise<Relative> {
return this.relativeService.create(profileId, relativeData);
}
}
25 changes: 25 additions & 0 deletions kyc-nest/src/relative/relative.entity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Entity, PrimaryGeneratedColumn, Column, ManyToOne } from 'typeorm';
import { Profile } from '../profile/profile.entity';

@Entity()
export class Relative {
@PrimaryGeneratedColumn()
id: string;

@Column()
firstName: string;

@Column()
lastName: string;

@Column()
relation: string;

@Column()
politicalInfluence?: boolean;

@ManyToOne(() => Profile, (profile) => profile.relatives, {
onDelete: 'CASCADE',
})
profile: Profile;
}
13 changes: 13 additions & 0 deletions kyc-nest/src/relative/relative.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Module } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { RelativeController } from './relative.controller';
import { RelativeService } from './relative.service';
import { Relative } from './relative.entity';
import { ProfileModule } from '../profile/profile.module';

@Module({
imports: [TypeOrmModule.forFeature([Relative]), ProfileModule],
controllers: [RelativeController],
providers: [RelativeService],
})
export class RelativeModule {}
26 changes: 26 additions & 0 deletions kyc-nest/src/relative/relative.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ProfileService } from '../profile/profile.service';
import { Relative } from './relative.entity';

@Injectable()
export class RelativeService {
constructor(
private readonly profileService: ProfileService,
@InjectRepository(Relative)
private relativeRepository: Repository<Relative>,
) {}

async create(
profileId: string,
relativeData: Partial<Relative>,
): Promise<Relative> {
const profile = await this.profileService.findById(profileId);

const relative = this.relativeRepository.create(relativeData);
relative.profile = profile;

return this.relativeRepository.save(relative);
}
}

0 comments on commit 26d30f1

Please sign in to comment.