Created
July 1, 2020 15:21
-
-
Save Miczeq22/6641edfc7ddd83b962bcda5803dbf7ca to your computer and use it in GitHub Desktop.
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
interface Dependencies { | |
customerRepository: CustomerRepository; | |
} | |
class RegisterCustomerCommandHandler extends CommandHandler< | |
RegisterCustomerCommand | |
> { | |
constructor(private readonly dependencies: Dependencies) { | |
super(REGISTER_CUSTOMER_COMMAND_TYPE); | |
} | |
public async execute({ payload }: RegisterCustomerCommand) { | |
const { customerRepository } = this.dependencies; | |
const { email } = payload; | |
const existingUser = await customerRepository.findByEmail(email); | |
if (existingUser) { | |
throw new Error(`User with email: "${email}" already exist.`); | |
} | |
await customerRepository.insert(payload); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment