-
-
Save johndowns/519fb48fd5d1afb879fd3dcb4e81ce34 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
function getCustomerId(document: OrderDocument): string { | |
// try to get the customer ID from the new format first | |
if (document.customer != undefined && document.customer.id != undefined) { | |
return document.customer.id; | |
} | |
// if that didn't work, try to get the customer ID from the old format | |
if (document.customerId != undefined) { | |
return document.customerId; | |
} | |
// if neither are present, that is an error | |
throw new Error("Document with id " + document.id + " does not contain customer ID in recognised format."); | |
} | |
interface OrderDocument { | |
id: string, | |
customerId: string, | |
customer: { | |
id: string | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment