in lambdas/src/MembershipSub-Reconstruct-PromoCode-View.js [16:66]
function generatePutRequest(campaignsByCode, channelName, promotion, tableName) {
return (promoCodeObj) => {
const campaignCode = promotion.campaignCode.S;
const promotionName = promotion.name.S;
if (!promotionName) {
return;
}
if (!campaignCode) {
return;
}
const campaignData = campaignsByCode[campaignCode];
if (!campaignData) {
return;
}
const promotionType = promotion.promotionType;
if (!(promotionType && promotionType.M && promotionType.M.name)) {
return;
}
const promotionTypeName = promotionType.M.name.S;
let discountPercent = 0;
let discountDurationMonths = 0;
if (promotionTypeName === 'percent_discount') {
if (promotionType.M.amount) {
discountPercent = parseInt(promotionType.M.amount.N, 10);
}
if (promotionType.M.durationMonths) {
discountDurationMonths = parseInt(promotionType.M.durationMonths.N, 10);
}
}
const promoCode = promoCodeObj.S;
if (!promoCode) {
return;
}
return {
TableName: tableName,
Item: {
channel_name: channelName,
promo_code: promoCode,
campaign_code: campaignCode,
promotion_name: promotionName,
campaign_name: campaignData.campaign_name,
product_family: campaignData.product_family,
promotion_type: promotionTypeName,
discount_percent: discountPercent,
discount_months: discountDurationMonths
}
};
};
}