39 lines
1.0 KiB
TypeScript
39 lines
1.0 KiB
TypeScript
import { RESTAURANT_REWARD_IDS, REWARD_IDS } from "@/constants/rewards"
|
|
|
|
import type {
|
|
RestaurantRewardId,
|
|
RewardId,
|
|
} from "@/types/components/myPages/rewards"
|
|
import type { Reward } from "@/server/routers/contentstack/reward/output"
|
|
|
|
export function isValidRewardId(id: string): id is RewardId {
|
|
return Object.values<string>(REWARD_IDS).includes(id)
|
|
}
|
|
|
|
export function isRestaurantReward(
|
|
rewardId: string
|
|
): rewardId is RestaurantRewardId {
|
|
return RESTAURANT_REWARD_IDS.some((id) => id === rewardId)
|
|
}
|
|
|
|
export function redeemLocationIsOnSite(
|
|
location: Reward["redeemLocation"]
|
|
): location is "On-site" {
|
|
return location === "On-site"
|
|
}
|
|
|
|
export function isTierType(type: Reward["rewardType"]): type is "Tier" {
|
|
return type === "Tier"
|
|
}
|
|
|
|
export function isOnSiteTierReward(reward: Reward): boolean {
|
|
return (
|
|
redeemLocationIsOnSite(reward.redeemLocation) &&
|
|
isTierType(reward.rewardType)
|
|
)
|
|
}
|
|
|
|
export function isRestaurantOnSiteTierReward(reward: Reward): boolean {
|
|
return isOnSiteTierReward(reward) && isRestaurantReward(reward.reward_id)
|
|
}
|