Created
May 13, 2019 17:55
-
-
Save barbaromatrix/2ddedcfdb7d0d909176656c7b36a5ccf to your computer and use it in GitHub Desktop.
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
const httpErrorCodes = [400, 500, 501, 504] | |
module.exports.checkForRequestError = (requestData, errorList = httpErrorCodes) => | |
requestData.statusCode && errorList.indexOf(requestData.statusCode > -1) | |
module.exports.setupActivationData = (requestParams, context, ee, next) => { | |
const coupons = context.vars.coupon_v2 | |
const filteredCoupons = coupons.find(coupon => !coupon.active) | |
context.vars.coupon_v2 = filteredCoupons ? filteredCoupons : coupons[0] | |
return next() | |
} | |
module.exports.isDataAllowedToBeUsed = (context) => { | |
if (exports.checkForRequestError(context.coupon_v2)) { | |
return false | |
} | |
const coupons = context.coupon_v2 || [] | |
return coupons.filter(coupon => coupon.active === false).length > 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment