added tons of features
This commit is contained in:
26
lib/schemas/admin/category.ts
Normal file
26
lib/schemas/admin/category.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import {z} from 'zod'
|
||||
|
||||
import {db} from '@/lib/db/prisma/client'
|
||||
|
||||
export const categoryLocaleSchema = z.object({
|
||||
lang: z.enum(['uk', 'ru']),
|
||||
title: z.string().trim().min(1).max(384),
|
||||
/*.refine(async current => {
|
||||
const count = await db.categoryLocale.count({
|
||||
where: {
|
||||
title: current
|
||||
}
|
||||
})
|
||||
|
||||
return count === 0
|
||||
}, "Імя категорії вже існує")*/
|
||||
// slug: z.string().trim().min(5, {
|
||||
// message: 'slug_required'
|
||||
// }),
|
||||
short_title: z.string().trim().max(384).optional(),
|
||||
description: z.string().trim().max(3840).optional()
|
||||
})
|
||||
|
||||
export const createCategoryFormSchema = z.object({
|
||||
locales: z.array(categoryLocaleSchema)
|
||||
})
|
||||
44
lib/schemas/admin/product.ts
Normal file
44
lib/schemas/admin/product.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import {z} from 'zod'
|
||||
|
||||
import {i18nLocalesCodes} from '@/i18n-config'
|
||||
import {metaFormSchema} from '@/lib/schemas/meta'
|
||||
|
||||
export const productLocaleSchema = z.object({
|
||||
lang: z.enum(i18nLocalesCodes),
|
||||
title: z.coerce.string().trim().min(1).max(384),
|
||||
shortTitle: z.coerce.string().trim().max(191).optional(),
|
||||
headingTitle: z.coerce.string().trim().max(191).optional(),
|
||||
description: z.coerce.string().trim(),
|
||||
content: z.coerce.string().trim().optional(),
|
||||
instruction: z.coerce.string().trim().optional()
|
||||
})
|
||||
|
||||
export const createProductFormSchema = z.object({
|
||||
image: z.coerce.string().trim().max(512).optional(),
|
||||
published: z.coerce.boolean().default(false).optional(), // ProductToStore
|
||||
price: z.coerce
|
||||
.string()
|
||||
.min(2)
|
||||
.regex(/^\d{1,7}(\.\d{1,2})?$/, {
|
||||
message: 'Максимум 7 цифр до крапки та 2 після неї'
|
||||
}), // ProductToStore
|
||||
pricePromotional: z.coerce
|
||||
.string()
|
||||
.regex(/^\d{1,7}(\.\d{1,2})?$/, {
|
||||
message: 'Максимум 7 цифр до крапки та 2 після неї'
|
||||
})
|
||||
.optional(), // ProductToStore
|
||||
locales: z.array(productLocaleSchema),
|
||||
meta: z.array(metaFormSchema)
|
||||
})
|
||||
|
||||
//
|
||||
// files: z
|
||||
// .array(
|
||||
// z.object({
|
||||
// file: z.any(),
|
||||
// alt: z.string().min(1, {message: 'Значення тегу Alt необхідне'}),
|
||||
// title: z.string().min(1, {message: 'Значення тегу title необхідне'})
|
||||
// })
|
||||
// )
|
||||
// .nonempty({message: 'Необхідно обрати хоча б один файл'})
|
||||
Reference in New Issue
Block a user