Skip to content

Commit

Permalink
[Booster] Milestone 1: Profile creation
Browse files Browse the repository at this point in the history
  • Loading branch information
javiertoledo committed Apr 25, 2023
1 parent 48601ff commit 8b8b360
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
28 changes: 28 additions & 0 deletions kyc-booster/src/commands/create-profile.ts
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))
}
}
1 change: 1 addition & 0 deletions kyc-booster/src/common/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export type KYCStatus = 'KYCPending'
28 changes: 28 additions & 0 deletions kyc-booster/src/entities/profile.ts
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)
}
}
26 changes: 26 additions & 0 deletions kyc-booster/src/events/profile-created.ts
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
}
}
30 changes: 30 additions & 0 deletions kyc-booster/src/read-models/ProfileReadModel.ts
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)
}
}

0 comments on commit 8b8b360

Please sign in to comment.