-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[NestJS] Milestone 5: Family and occupation risk assessment
- Loading branch information
1 parent
41cd187
commit 26d30f1
Showing
8 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |