function generatePutRequestFromDynamoPromoCodeObject()

in lambdas/src/MembershipSub-Promotions-to-PromoCode-View-Lambda.js [28:64]


function generatePutRequestFromDynamoPromoCodeObject(promoCodeObj, newImage, channelName) {
    if (!(promoCodeObj && newImage.campaignCode && newImage.name)) { return; }

    const promoCode = promoCodeObj.S;
    if (!promoCode) { return; }
    const campaignCode = newImage.campaignCode.S;
    const promotionName = newImage.name.S;
    if (!promotionName) { return; }
    if (!campaignCode) { return; }
    const campaignData = campaignDetailsByCampaignCode[campaignCode];
    if (!campaignData) { return; }
    const promotionType = newImage.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') {
        discountPercent = parseInt(promotionType.M.amount.N, 10);
        discountDurationMonths = parseInt(promotionType.M.durationMonths.N, 10);
    }

    putRequestsByPromoCode[promoCode] = {
        PutRequest: {
            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
            }
        }
    };
}