Untitled
unknown
plain_text
9 months ago
2.2 kB
7
Indexable
const assetSchema = z
.array(
z.object({
type: z.enum(['video', 'image']),
name: z.string(),
id: z.number(),
url: z.string(),
assetId: z.string(),
publicId: z.string(),
blurDataUrl: z.string(),
key: z.string(),
}),
)
.min(1, 'At least one asset is required.');
const rootSchema = z.object({
assets: assetSchema,
name: z.string().trim().min(1, 'Name is required.'),
description: z
.string()
.trim()
.refine(
(arg) => (arg ? arg.length >= 100 : true),
'At least 100 characters are required.',
),
brand: z
.object({ id: z.number(), name: z.string() })
.nullable()
.refine((arg) => arg, 'Brand is required.'),
category: z
.object({ id: z.number(), name: z.string() })
.nullable()
.refine((arg) => arg, 'Category is required.'),
returnPolicy: z
.object({ id: z.number(), name: z.string() })
.nullable()
.refine((arg) => arg, 'Return Policy is required.'),
featured: z.boolean(),
active: z.boolean(),
haveOptions: z.boolean(),
});
const haveOptionsSchema = rootSchema.extend({
variants: z
.array(
productVariantSchema
.omit({ assets: true, combination: true })
.extend({
assets: assetSchema,
combination: z
.array(z.object({ id: z.number(), value: z.string() }))
.min(1, 'Combination is required.'),
}),
)
.min(1, 'At least one variant is required.'),
options: z
.array(
z.object({
name: z
.object({
id: z.number(),
name: z.string(),
isColor: z.boolean(),
})
.nullable()
.refine((arg) => arg, 'Name is required.'),
choices: z
.array(z.object({ id: z.number(), value: z.string() }))
.min(1, 'At least one choice is required.'),
}),
)
.min(1, 'At least one option is required.'),
});
const noOptionsSchema = rootSchema.merge(productSharedFields);
type HaveOptions = z.infer<typeof haveOptionsSchema>;
type NoOptions = z.infer<typeof noOptionsSchema>;Editor is loading...
Leave a Comment