Created
December 3, 2022 05:47
-
-
Save leegilmorecode/a20b0a9695db769f2d0074b56aedca4b to your computer and use it in GitHub Desktop.
Create customer account use case example
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
import { | |
CustomerAccountDto, | |
NewCustomerAccountDto, | |
} from '@dto/customer-account'; | |
import { CustomerAccount } from '@domain/customer-account'; | |
import { createCustomerAccount } from '@repositories/create-customer-account-repository'; | |
import { logger } from '@packages/logger'; | |
import { publishDomainEvents } from '@repositories/publish-event-recipient'; | |
// takes a dto and calls the domain entities (returning a dto to the primary adapter) | |
// adapter --> (use case) --> domain & repositories | |
/** | |
* Create a new Customer Account | |
* Input: NewCustomerAccountDto | |
* Output: CustomerAccountDto | |
* | |
* Primary course: | |
* | |
* 1. Validate the customer account details | |
* 2. Create a new customer account | |
* 3. Publish a CustomerAccountCreated event. | |
*/ | |
export async function createCustomerAccountUseCase( | |
account: NewCustomerAccountDto | |
): Promise<CustomerAccountDto> { | |
const newCustomer: CustomerAccount = CustomerAccount.createAccount(account); | |
await createCustomerAccount(newCustomer); | |
logger.info(`customer account created for ${newCustomer.id}`); | |
await publishDomainEvents(newCustomer.retrieveDomainEvents()); | |
return newCustomer.toDto(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment