chore(LOY-175): remove references to old reward endpoints

This commit is contained in:
Christian Andolf
2025-03-10 13:35:07 +01:00
parent 4ff44311a9
commit 0ae4c5db17
8 changed files with 13 additions and 193 deletions

View File

@@ -1,4 +1,3 @@
import { env } from "@/env/server"
import * as api from "@/lib/api"
import { dt } from "@/lib/dt"
import { notFound } from "@/server/errors/trpc"
@@ -20,11 +19,9 @@ import {
import {
type Reward,
type Surprise,
validateApiRewardSchema,
validateCategorizedRewardsSchema,
} from "./output"
import {
getAllCachedApiRewards,
getAllRewardCounter,
getAllRewardFailCounter,
getAllRewardSuccessCounter,
@@ -52,9 +49,7 @@ export const rewardQueryRouter = router({
.query(async function ({ input, ctx }) {
getAllRewardCounter.add(1)
const allApiRewards = env.USE_NEW_REWARDS_ENDPOINT
? await getCachedAllTierRewards(ctx.serviceToken)
: await getAllCachedApiRewards(ctx.serviceToken)
const allApiRewards = await getCachedAllTierRewards(ctx.serviceToken)
if (!allApiRewards) {
return []
@@ -114,9 +109,9 @@ export const rewardQueryRouter = router({
getByLevelRewardCounter.add(1)
const { level_id } = input
const allUpcomingApiRewards = env.USE_NEW_REWARDS_ENDPOINT
? await getCachedAllTierRewards(ctx.serviceToken)
: await getAllCachedApiRewards(ctx.serviceToken)
const allUpcomingApiRewards = await getCachedAllTierRewards(
ctx.serviceToken
)
if (!allUpcomingApiRewards || !allUpcomingApiRewards[level_id]) {
getByLevelRewardFailCounter.add(1)
@@ -167,10 +162,7 @@ export const rewardQueryRouter = router({
.query(async function ({ ctx }) {
getCurrentRewardCounter.add(1)
const isNewEndpoint = env.USE_NEW_REWARDS_ENDPOINT
const endpoint = isNewEndpoint
? api.endpoints.v1.Profile.Reward.reward
: api.endpoints.v1.Profile.reward
const endpoint = api.endpoints.v1.Profile.Reward.reward
const apiResponse = await api.get(endpoint, {
headers: {
@@ -203,9 +195,8 @@ export const rewardQueryRouter = router({
const data = await apiResponse.json()
const validatedApiRewards = isNewEndpoint
? validateCategorizedRewardsSchema.safeParse(data)
: validateApiRewardSchema.safeParse(data)
const validatedApiRewards =
validateCategorizedRewardsSchema.safeParse(data)
if (!validatedApiRewards.success) {
getCurrentRewardFailCounter.add(1, {
@@ -301,10 +292,7 @@ export const rewardQueryRouter = router({
.query(async ({ ctx }) => {
getCurrentRewardCounter.add(1)
const isNewEndpoint = env.USE_NEW_REWARDS_ENDPOINT
const endpoint = isNewEndpoint
? api.endpoints.v1.Profile.Reward.reward
: api.endpoints.v1.Profile.reward
const endpoint = api.endpoints.v1.Profile.Reward.reward
const apiResponse = await api.get(endpoint, {
cache: undefined,
@@ -337,9 +325,8 @@ export const rewardQueryRouter = router({
}
const data = await apiResponse.json()
const validatedApiRewards = isNewEndpoint
? validateCategorizedRewardsSchema.safeParse(data)
: validateApiRewardSchema.safeParse(data)
const validatedApiRewards =
validateCategorizedRewardsSchema.safeParse(data)
if (!validatedApiRewards.success) {
getCurrentRewardFailCounter.add(1, {