Skip to content

Conversation

@tomrf1
Copy link
Member

@tomrf1 tomrf1 commented Jan 8, 2026

We're migrating to a new promos tool, with a new Dynamodb table and a simplified schema.
The old tool/table is still in use. Data is currently being sync'd from the v1 table to the v2 table.

Currently we have v1 and v2 versions of the schemas:
Screenshot 2026-01-08 at 13 43 59

This PR adds equivalent functions to replace the use of the v1 table:
Screenshot 2026-01-08 at 13 45 18

It also refactors the zuora code to use the v2 versions.
The biggest change here is that instead of performing a full scan of the promos table, it now gets the specific item by promoCode. This wasn't possible with the old schema because each item could have many promo codes nested in it.
This is why getPromotions is being replaced by getPromotion.

This code is used by support-workers.
Once this is released we can update support-workers to use it.

@tomrf1 tomrf1 added the feature Departmental tracking: work on a new feature label Jan 8, 2026

export type Promo = z.infer<typeof promoSchema>;

export const appliedPromotionSchema = z.object({
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied from the v1 schema

promoCode: string;
};

export const validatePromotion = (
Copy link
Member Author

@tomrf1 tomrf1 Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return parseResult.data;
};

export const getDiscountRatePlanFromCatalog = (
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copied from v1/getPromotions.ts


const dynamoClient = new DynamoDBClient(awsConfig);

export const getPromotion = async (
Copy link
Member Author

@tomrf1 tomrf1 Jan 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomrf1 tomrf1 changed the title Tf use v2 promos Use v2 promos table Jan 8, 2026
@tomrf1 tomrf1 requested a review from rupertbates January 8, 2026 14:21
} from '@modules/internationalisation/schemas';
import { z } from 'zod';

export const promoProductSchema = z.enum([
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realise this was not introduced in this PR but we should be using the product catalog values for this.

There is a schema called productKeySchema which lists these here:

export const productKeySchema = z.enum(productKeys);

Possibly we could add another schema which is a subset of these as not all will be discountable, but we should really try and work with the same product names across our whole code base.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The complication is that in the promo tool the concept of PromoCampaign groups several product rate plans into one "product", e.g. Newspaper.
This promoProductSchema is only relevant to PromoCampaigns. At the level of individual promo codes we map direct to a set of rate plan ids

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps we could make this clearer by inlining this enum in the promoCampaignSchema

? validatePromotion(promotions, appliedPromotion, productRatePlanId)
: undefined;
const validatedPromotion =
appliedPromotion && promotion
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should fail at this point if we have an applied promotion but not a promotion as that will mean we have told the user they are getting a discount which they will not then get.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot. I've pushed a commit to handle this in validatePromotion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Departmental tracking: work on a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants