Merged in feat/membership-schema-update (pull request #1459)
Update membership schema to adapt for API changes Approved-by: Michael Zetterberg
This commit is contained in:
@@ -2,17 +2,14 @@ import { z } from "zod"
|
||||
|
||||
import { countriesMap } from "@/constants/countries"
|
||||
|
||||
import { getMembership } from "@/utils/user"
|
||||
import { getMembership, scandicMemberships } from "@/utils/user"
|
||||
|
||||
import { imageSchema } from "../hotels/schemas/image"
|
||||
|
||||
export const membershipSchema = z.object({
|
||||
currentPoints: z.number(),
|
||||
expirationDate: z.string(),
|
||||
membershipNumber: z.string(),
|
||||
const commonMembershipSchema = z.object({
|
||||
currentPoints: z.number().optional(),
|
||||
expirationDate: z.string().optional(),
|
||||
membershipLevel: z.string().optional(),
|
||||
memberSince: z.string(),
|
||||
membershipType: z.string(),
|
||||
nextLevel: z.string().optional(),
|
||||
nightsToTopTier: z.number().optional(),
|
||||
pointsExpiryDate: z.string().optional(),
|
||||
@@ -21,6 +18,34 @@ export const membershipSchema = z.object({
|
||||
tierExpirationDate: z.string().optional(),
|
||||
})
|
||||
|
||||
const membershipType = (membershipType: scandicMemberships) =>
|
||||
z
|
||||
.string()
|
||||
// The memberships enum is in lower case so this makes sure it will match regardless of casing in the API response.
|
||||
.transform((s) => s.toLowerCase())
|
||||
.pipe(z.literal(membershipType))
|
||||
|
||||
const friendsMembershipSchema = z
|
||||
.object({
|
||||
membershipType: membershipType(scandicMemberships.guestpr),
|
||||
membershipNumber: z.string(),
|
||||
memberSince: z.string(),
|
||||
})
|
||||
.merge(commonMembershipSchema)
|
||||
|
||||
const otherMembershipSchema = z
|
||||
.object({
|
||||
membershipType: z.string(),
|
||||
membershipNumber: z.string().optional(),
|
||||
memberSince: z.string().optional(),
|
||||
})
|
||||
.merge(commonMembershipSchema)
|
||||
|
||||
export const membershipSchema = z.union([
|
||||
friendsMembershipSchema,
|
||||
otherMembershipSchema,
|
||||
])
|
||||
|
||||
export const getUserSchema = z
|
||||
.object({
|
||||
data: z.object({
|
||||
|
||||
Reference in New Issue
Block a user