Last active
July 19, 2016 22:00
-
-
Save johntran/fa61c65575108277997844f80c94a129 to your computer and use it in GitHub Desktop.
Function Parameter Default Pattern
This file contains hidden or 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
/** | |
* Let's say you have | |
* function getPromoCodeErrors(accountId, cart, cartProductItems, cartItems) | |
* | |
* If you don't have one or more of these parameters, then you need nulls in to fill out the parameters | |
* getPromoCodeErrors(accountId, null, null, cartItems) | |
* | |
* With the below this is valid | |
* getPromoCodeErrors({accountId, cartItems}) | |
* | |
* This too | |
* getPromoCodeErrors({accountId, cartProductItems, cartItems, cart}) | |
* | |
* This too | |
* getPromoCodeErrors() | |
* | |
* Line 24 sets an empty parameter to an object. | |
*/ | |
export async function getPromoCodeErrors({ | |
accountId = '', | |
cart = {}, | |
cartProductItems = [], | |
cartItems = {}, | |
} = {}) { | |
const promoCodeInfo = await getPromoCodeByCode(accountId, cart.promoCodes[0]); | |
const orderItems = getOrderItems(cart, cartProductItems); | |
const { validProducts, validCategories } = checkPromoCodeValidityForCart(cart, cartItems, promoCodeInfo); | |
const { promoCodeError } = await checkPromoCodeThresholds({ | |
cart, | |
cartProductItems, | |
orderItems, | |
promoCode: promoCodeInfo, | |
validProducts, | |
validCategories | |
}); | |
return promoCodeError | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment