Last active
August 18, 2022 17:04
-
-
Save JAStanton/72cbd0fb882a9620a94a2d4d13f51ae6 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
{ | |
"promo": "NTDAW", | |
"restriction": { | |
"type": "DATE", | |
"start": "...", | |
"end": "...", | |
"tz": "America/Los_Angeles" | |
} | |
} |
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
enum PromoValues { | |
NONE, | |
} | |
enum RestrictionType { | |
DATE, | |
} | |
async function getPaymentSpeedDefinitions(context) { | |
let promoType = PROMO_TYPE.NONE; | |
if (await tdClient.isSwitchOn(PROMOTIONS)) { | |
promoType = await getPromoType(context); | |
} | |
return await context.dao.paymentSpeed.findAllPOaymentSpeedDefinitions(promoType); | |
} | |
async function getPromoType(context): PromoType { | |
const flagResult = await tdclient.getFlag(flag_name, { carrierId: context.carrierId }) | |
const promoDetails = flagResult.jsonValues(); | |
if (!promoDetails) { | |
return PromoValues.NONE; | |
} | |
const { restriction, promoType } = promoDetails; | |
switch (restriction.type as RestrictionType) { | |
case RestrictionType.DATE: | |
return getDateRestrictionType(promoDetails); | |
case DEFAULT: | |
console.error('unsupported promo type', { context } ); | |
return PromoValues.NONE; | |
} | |
} | |
function getDateRestrictionType({ restriction: { start, end, tz }, promoType }) { | |
const now = moment.tz(tz); | |
const start = moment.tz(tz, start); | |
const end = moment.tz(tz, end); | |
if (now.between(start, end)) { | |
return promoType; | |
} | |
return PromoValues.NONE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment