fix(LOY-119): hiding redeemed rewards
some smaller cleanup on coupon property to avoid optional checks
This commit is contained in:
@@ -11,6 +11,8 @@ import { notFound } from "@/server/errors/trpc"
|
||||
import { generateLoyaltyConfigTag } from "@/utils/generateTag"
|
||||
|
||||
import {
|
||||
type ApiReward,
|
||||
type CategorizedApiReward,
|
||||
type CmsRewardsResponse,
|
||||
type CmsRewardsWithRedeemResponse,
|
||||
validateApiAllTiersSchema,
|
||||
@@ -264,3 +266,20 @@ export async function getCmsRewards(locale: Lang, rewardIds: string[]) {
|
||||
|
||||
return validatedCmsRewards.data
|
||||
}
|
||||
|
||||
export function getNonRedeemedRewardIds(
|
||||
rewards: Array<ApiReward | CategorizedApiReward>
|
||||
) {
|
||||
return rewards
|
||||
.filter((reward) => {
|
||||
if ("coupon" in reward && reward.coupon.length > 0) {
|
||||
if (reward.coupon.every((coupon) => coupon.state === "redeemed")) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
})
|
||||
.map((reward) => reward?.rewardId)
|
||||
.filter((rewardId): rewardId is string => !!rewardId)
|
||||
.sort()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user