Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
export class SequelizeCustomerLoader implements CustomerLoader {
async get(id: string): Promise<Customer> {
const customers = await SequelizeCustomerModel
.findAll({
where: { id: id },
limit: 1
})
.then(this.mapToCustomers)
return customers[0] || Promise.reject(new CustomerNotFoundError())
}
private mapToCustomers(customers: SequelizeCustomerModel[]): Customer[] {
return customers.map(customer => new Customer(
customer.id,
customer.name,
customer.email,
customer.phone
))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.