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
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