chore(LOY-175): remove references to old reward endpoints
This commit is contained in:
@@ -17,14 +17,12 @@ import {
|
||||
} from "@/utils/generateTag"
|
||||
|
||||
import {
|
||||
type ApiReward,
|
||||
type CategorizedApiReward,
|
||||
type CmsRewardsResponse,
|
||||
type CmsRewardsWithRedeemResponse,
|
||||
type GetRewardWithRedeemRefsSchema,
|
||||
rewardWithRedeemRefsSchema,
|
||||
validateApiAllTiersSchema,
|
||||
validateApiTierRewardsSchema,
|
||||
validateCmsRewardsSchema,
|
||||
validateCmsRewardsWithRedeemSchema,
|
||||
} from "./output"
|
||||
@@ -93,71 +91,6 @@ export function getUniqueRewardIds(rewardIds: string[]) {
|
||||
return Array.from(uniqueRewardIds)
|
||||
}
|
||||
|
||||
/**
|
||||
* Uses the legacy profile/v1/Profile/tierRewards endpoint.
|
||||
* TODO: Delete when the new endpoint is out in production.
|
||||
*/
|
||||
export async function getAllCachedApiRewards(token: string) {
|
||||
const cacheClient = await getCacheClient()
|
||||
|
||||
return await cacheClient.cacheOrGet(
|
||||
"getAllApiRewards",
|
||||
async () => {
|
||||
const apiResponse = await api.get(api.endpoints.v1.Profile.tierRewards, {
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
|
||||
if (!apiResponse.ok) {
|
||||
const text = await apiResponse.text()
|
||||
getAllRewardFailCounter.add(1, {
|
||||
error_type: "http_error",
|
||||
error: JSON.stringify({
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
}),
|
||||
})
|
||||
console.error(
|
||||
"api.rewards.tierRewards error ",
|
||||
JSON.stringify({
|
||||
error: {
|
||||
status: apiResponse.status,
|
||||
statusText: apiResponse.statusText,
|
||||
text,
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
throw apiResponse
|
||||
}
|
||||
|
||||
const data = await apiResponse.json()
|
||||
const validatedApiTierRewards =
|
||||
validateApiTierRewardsSchema.safeParse(data)
|
||||
|
||||
if (!validatedApiTierRewards.success) {
|
||||
getAllRewardFailCounter.add(1, {
|
||||
error_type: "validation_error",
|
||||
error: JSON.stringify(validatedApiTierRewards.error),
|
||||
})
|
||||
console.error(validatedApiTierRewards.error)
|
||||
console.error(
|
||||
"api.rewards validation error",
|
||||
JSON.stringify({
|
||||
error: validatedApiTierRewards.error,
|
||||
})
|
||||
)
|
||||
throw validatedApiTierRewards.error
|
||||
}
|
||||
|
||||
return validatedApiTierRewards.data
|
||||
},
|
||||
"1h"
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Cached for 1 hour.
|
||||
*/
|
||||
@@ -364,9 +297,7 @@ export async function getCmsRewards(lang: Lang, rewardIds: string[]) {
|
||||
return validatedCmsRewards.data
|
||||
}
|
||||
|
||||
export function getNonRedeemedRewardIds(
|
||||
rewards: Array<ApiReward | CategorizedApiReward>
|
||||
) {
|
||||
export function getNonRedeemedRewardIds(rewards: Array<CategorizedApiReward>) {
|
||||
return rewards
|
||||
.filter((reward) => {
|
||||
if ("coupon" in reward && reward.coupon.length > 0) {
|
||||
|
||||
Reference in New Issue
Block a user