in src/server/lib/superMode.ts [30:103]
countryGroupId: regionToCountryGroupId(record.region),
}));
};
export const buildSuperModeArticlesReloader = (): Promise<ValueReloader<SuperModeArticle[]>> =>
buildReloader(fetchSuperModeArticles, 60);
export const isInSuperMode = (
url: string,
countryGroupId: CountryGroupId,
superModeArticles: SuperModeArticle[],
): boolean => {
return superModeArticles.some((a) => a.url === url && a.countryGroupId === countryGroupId);
};
export const superModeify = (test?: EpicTest): EpicTest | undefined => {
return test && { ...test, isSuperMode: true };
};
type Region = 'GB' | 'US' | 'AU' | 'NZ' | 'CA' | 'EU' | 'ROW';
interface DynamoRecord {
id: string;
startTimestamp: string;
endDate: string;
endTimestamp: string;
url: string;
region: Region;
totalAv: number;
totalViews: number;
avPerView: number;
}
const REGION_TO_COUNTRY_GROUP: Record<Region, CountryGroupId> = {
GB: 'GBPCountries',
US: 'UnitedStates',
AU: 'AUDCountries',
NZ: 'NZDCountries',
CA: 'Canada',
EU: 'EURCountries',
ROW: 'International',
};
function regionToCountryGroupId(region: Region): CountryGroupId {
return REGION_TO_COUNTRY_GROUP[region];
}
export async function queryActiveArticles(
stage: string,
docClient: AWS.DynamoDB.DocumentClient,
now: Date = new Date(),
): Promise<DynamoRecord[]> {
const tomorrow = addDays(now, 1);
const todayEndDate = toDateString(now);
const tomorrowEndDate = toDateString(tomorrow);
const endTimestamp = toDateHourString(now);
const [todayResult, tomorrowResult] = await Promise.all([
queryDate(todayEndDate, endTimestamp, stage, docClient),
queryDate(tomorrowEndDate, endTimestamp, stage, docClient),
]);
return [...(todayResult.Items ?? []), ...(tomorrowResult.Items ?? [])] as DynamoRecord[];
}
function queryDate(
endDate: string,
endTimestamp: string,
stage: string,
docClient: AWS.DynamoDB.DocumentClient,
) {
return docClient
.query({