feat(SW-739): use new allTiers endpoint and add feature flag

This commit is contained in:
Chuma McPhoy
2024-11-08 14:50:18 +01:00
parent 35a527be05
commit 48af26a772
7 changed files with 107 additions and 8 deletions

View File

@@ -1,3 +1,4 @@
import { env } from "@/env/server"
import * as api from "@/lib/api"
import { notFound } from "@/server/errors/trpc"
import {
@@ -22,6 +23,7 @@ import {
getByLevelRewardCounter,
getByLevelRewardFailCounter,
getByLevelRewardSuccessCounter,
getCachedAllTierRewards,
getCmsRewards,
getCurrentRewardCounter,
getCurrentRewardFailCounter,
@@ -36,7 +38,10 @@ export const rewardQueryRouter = router({
.input(rewardsAllInput)
.query(async function ({ input, ctx }) {
getAllRewardCounter.add(1)
const allApiRewards = await getAllCachedApiRewards(ctx.serviceToken)
const allApiRewards = !!env.USE_NEW_REWARDS_ENDPOINT
? await getCachedAllTierRewards(ctx.serviceToken)
: await getAllCachedApiRewards(ctx.serviceToken)
if (!allApiRewards) {
return []
@@ -96,9 +101,9 @@ export const rewardQueryRouter = router({
getByLevelRewardCounter.add(1)
const { level_id } = input
const allUpcomingApiRewards = await getAllCachedApiRewards(
ctx.serviceToken
)
const allUpcomingApiRewards = !!env.USE_NEW_REWARDS_ENDPOINT
? await getCachedAllTierRewards(ctx.serviceToken)
: await getAllCachedApiRewards(ctx.serviceToken)
if (!allUpcomingApiRewards || !allUpcomingApiRewards[level_id]) {
getByLevelRewardFailCounter.add(1)