-
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.
[Booster] Milestone 1: Profile creation
- Loading branch information
1 parent
48601ff
commit 8b8b360
Showing
5 changed files
with
113 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { Command } from '@boostercloud/framework-core' | ||
import { Register, UUID } from '@boostercloud/framework-types' | ||
import { ProfileCreated } from '../events/profile-created' | ||
|
||
@Command({ | ||
authorize: 'all', // Or specify authorized roles | ||
}) | ||
export class CreateProfile { | ||
public constructor( | ||
readonly firstName: string, | ||
readonly lastName: string, | ||
readonly address: string, | ||
readonly city: string, | ||
readonly state: string, | ||
readonly zipCode: string, | ||
readonly dateOfBirth: string, | ||
readonly phoneNumber: string, | ||
readonly email: string, | ||
readonly ssn?: string, | ||
readonly tin?: string, | ||
) {} | ||
|
||
public static async handle(command: CreateProfile, register: Register): Promise<void> { | ||
const profileId = UUID.generate() | ||
const kycStatus = 'KYCPending' | ||
register.events(new ProfileCreated(profileId, command.firstName, command.lastName, command.address, command.city, command.state, command.zipCode, command.dateOfBirth, command.phoneNumber, command.email, kycStatus, command.ssn, command.tin)) | ||
} | ||
} |
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 @@ | ||
export type KYCStatus = 'KYCPending' |
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,28 @@ | ||
import { UUID } from '@boostercloud/framework-types' | ||
import { Entity, Reduces } from '@boostercloud/framework-core' | ||
import { ProfileCreated } from '../events/profile-created' | ||
import { KYCStatus } from '../common/types' | ||
|
||
@Entity | ||
export class Profile { | ||
public constructor( | ||
public id: UUID, | ||
readonly firstName: string, | ||
readonly lastName: string, | ||
readonly address: string, | ||
readonly city: string, | ||
readonly state: string, | ||
readonly zipCode: string, | ||
readonly dateOfBirth: string, | ||
readonly phoneNumber: string, | ||
readonly email: string, | ||
readonly kycStatus: KYCStatus, | ||
readonly ssn?: string, | ||
readonly tin?: string, | ||
) {} | ||
|
||
@Reduces(ProfileCreated) | ||
public static reduceProfileCreated(event: ProfileCreated, currentProfile?: Profile): Profile { | ||
return new Profile(event.profileId, event.firstName, event.lastName, event.address, event.city, event.state, event.zipCode, event.dateOfBirth, event.phoneNumber, event.email, event.kycStatus, event.ssn, event.tin) | ||
} | ||
} |
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 { Event } from '@boostercloud/framework-core' | ||
import { UUID } from '@boostercloud/framework-types' | ||
import { KYCStatus } from '../common/types' | ||
|
||
@Event | ||
export class ProfileCreated { | ||
public constructor( | ||
readonly profileId: UUID, | ||
readonly firstName: string, | ||
readonly lastName: string, | ||
readonly address: string, | ||
readonly city: string, | ||
readonly state: string, | ||
readonly zipCode: string, | ||
readonly dateOfBirth: string, | ||
readonly phoneNumber: string, | ||
readonly email: string, | ||
readonly kycStatus: KYCStatus, | ||
readonly ssn?: string, | ||
readonly tin?: string, | ||
) {} | ||
|
||
public entityID(): UUID { | ||
return this.profileId | ||
} | ||
} |
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,30 @@ | ||
import { Projects, ReadModel } from '@boostercloud/framework-core' | ||
import { ProjectionResult, UUID } from '@boostercloud/framework-types' | ||
import { Profile } from '../entities/profile' | ||
import { KYCStatus } from '../common/types' | ||
|
||
@ReadModel({ | ||
authorize: 'all', // You can specify roles to restrict access to this read model | ||
}) | ||
export class ProfileReadModel { | ||
public constructor( | ||
public id: UUID, | ||
readonly firstName: string, | ||
readonly lastName: string, | ||
readonly address: string, | ||
readonly city: string, | ||
readonly state: string, | ||
readonly zipCode: string, | ||
readonly dateOfBirth: string, | ||
readonly phoneNumber: string, | ||
readonly email: string, | ||
readonly kycStatus: KYCStatus, | ||
readonly ssn?: string, | ||
readonly tin?: string, | ||
) {} | ||
|
||
@Projects(Profile, 'id') | ||
public static projectProfile(entity: Profile): ProjectionResult<ProfileReadModel> { | ||
return new ProfileReadModel(entity.id, entity.firstName, entity.lastName, entity.address, entity.city, entity.state, entity.zipCode, entity.dateOfBirth, entity.phoneNumber, entity.email, entity.kycStatus, entity.ssn, entity.tin) | ||
} | ||
} |