-
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 1: Profile creation
- Loading branch information
1 parent
a629622
commit 48601ff
Showing
5 changed files
with
120 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Controller, Get, Param, Post, Body } from '@nestjs/common'; | ||
import { ProfileService } from './profile.service'; | ||
import { Profile } from './profile.entity'; | ||
|
||
@Controller('profiles') | ||
export class ProfileController { | ||
constructor(private readonly profileService: ProfileService) {} | ||
|
||
@Post() | ||
async create(@Body() profileData: Profile): Promise<Profile> { | ||
return this.profileService.create(profileData); | ||
} | ||
|
||
@Get() | ||
async findAll(): Promise<Profile[]> { | ||
return this.profileService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
async findById(@Param('id') id: string): Promise<Profile> { | ||
return this.profileService.findById(id); | ||
} | ||
} |
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,45 @@ | ||
import { Entity, PrimaryGeneratedColumn, Column } from 'typeorm'; | ||
|
||
export type KYCStatus = 'KYCPending'; | ||
|
||
@Entity() | ||
export class Profile { | ||
@PrimaryGeneratedColumn() | ||
id: string; | ||
|
||
@Column() | ||
firstName: string; | ||
|
||
@Column() | ||
lastName: string; | ||
|
||
@Column() | ||
address: string; | ||
|
||
@Column() | ||
city: string; | ||
|
||
@Column() | ||
state: string; | ||
|
||
@Column() | ||
zipCode: string; | ||
|
||
@Column() | ||
dateOfBirth: Date; | ||
|
||
@Column() | ||
phoneNumber: string; | ||
|
||
@Column() | ||
email: string; | ||
|
||
@Column({ nullable: true }) | ||
ssn?: string; | ||
|
||
@Column({ nullable: true }) | ||
tin?: string; | ||
|
||
@Column({ default: 'KYCPending' }) | ||
kycStatus: KYCStatus; | ||
} |
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,12 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ProfileController } from './profile.controller'; | ||
import { ProfileService } from './profile.service'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { Profile } from './profile.entity'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([Profile])], | ||
controllers: [ProfileController], | ||
providers: [ProfileService], | ||
}) | ||
export class ProfileModule {} |
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,38 @@ | ||
import { BadRequestException, Injectable } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { FindOneOptions, Repository } from 'typeorm'; | ||
import { KYCStatus, Profile } from './profile.entity'; | ||
import { NotFoundException } from '@nestjs/common'; | ||
|
||
@Injectable() | ||
export class ProfileService { | ||
constructor( | ||
@InjectRepository(Profile) | ||
private readonly profileRepository: Repository<Profile>, | ||
) {} | ||
|
||
async create(profileData: Profile): Promise<Profile> { | ||
const newProfile = this.profileRepository.create({ | ||
...profileData, | ||
kycStatus: 'KYCPending', | ||
}); | ||
await this.profileRepository.save(newProfile); | ||
return newProfile; | ||
} | ||
|
||
async findAll(): Promise<Profile[]> { | ||
return this.profileRepository.find(); | ||
} | ||
|
||
async findById(id: string): Promise<Profile> { | ||
const options: FindOneOptions<Profile> = { | ||
where: { id }, | ||
}; | ||
|
||
const profile = await this.profileRepository.findOne(options); | ||
if (!profile) { | ||
throw new NotFoundException(`Profile with ID "${id}" not found`); | ||
} | ||
return profile; | ||
} | ||
} |