stuff done
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
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),
|
||||
|
||||
43
lib/schemas/admin/entity.ts
Normal file
43
lib/schemas/admin/entity.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import {Entity, EntityLocale, EntityType} from '@prisma/client'
|
||||
import {z} from 'zod'
|
||||
|
||||
import {i18nLocalesCodes} from '@/i18n-config'
|
||||
import {metaFormSchema} from '@/lib/schemas/meta'
|
||||
|
||||
interface Map {
|
||||
[key: string]: string | undefined
|
||||
}
|
||||
|
||||
export const EntityTypeDescription: Map = {
|
||||
article: 'Стаття',
|
||||
page: 'Сторінка',
|
||||
block: 'Блок'
|
||||
}
|
||||
//
|
||||
export type EntityTerm = Entity & {locales: EntityLocale}
|
||||
|
||||
export const entityLocaleSchema = z.object({
|
||||
lang: z.enum(i18nLocalesCodes),
|
||||
title: z.coerce.string().trim().min(1).max(384),
|
||||
annotation: z.coerce.string().trim().optional(),
|
||||
body: z.coerce.string().trim().optional()
|
||||
})
|
||||
|
||||
export const createEntityFormSchema = z.object({
|
||||
type: z.enum(Object.keys(EntityType) as [string, ...string[]], {
|
||||
message: "Обов'язкове до вибору"
|
||||
}), // ProductToStore
|
||||
published: z.coerce.boolean().default(false).optional(), // ProductToStore
|
||||
scopes: z.coerce.string().trim().optional(),
|
||||
slug: z.coerce
|
||||
.string()
|
||||
.trim()
|
||||
.max(512)
|
||||
.regex(/^[a-z0-9-]+$/, {
|
||||
message: 'тільки латинські символи, цифри та дефіс'
|
||||
})
|
||||
.optional(),
|
||||
media: z.coerce.string().trim().max(512).optional(),
|
||||
locales: z.array(entityLocaleSchema),
|
||||
meta: z.array(metaFormSchema)
|
||||
})
|
||||
38
lib/schemas/admin/order.ts
Normal file
38
lib/schemas/admin/order.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import {DeliveryOption, Lang, Order} from '@prisma/client'
|
||||
import {z} from 'zod'
|
||||
|
||||
interface Map {
|
||||
[key: string]: string | undefined
|
||||
}
|
||||
|
||||
export const DeliveryOptionTypeDescription: Map = {
|
||||
NP: 'До відділення «Нової Пошти»',
|
||||
PICKUP: 'Самовивіз (для Києва)',
|
||||
COURIER: "Кур'єр (для Києва)"
|
||||
}
|
||||
|
||||
export const createOrderFormSchema = z.object({
|
||||
user_id: z.string().optional(),
|
||||
is_quick: z.boolean(),
|
||||
lang: z.enum(Object.keys(Lang) as [string, ...string[]]),
|
||||
first_name: z.coerce.string().trim().min(1).max(255),
|
||||
//patronymic: z.coerce.string().trim().min(1).max(255),
|
||||
surname: z.coerce.string().trim().min(1).max(255),
|
||||
delivery_option: z.enum(
|
||||
Object.keys(DeliveryOption) as [string, ...string[]],
|
||||
{
|
||||
message: "Обов'язкове до вибору"
|
||||
}
|
||||
),
|
||||
phone: z.coerce.string().trim().min(1).max(24),
|
||||
email: z.coerce
|
||||
.string()
|
||||
.trim()
|
||||
.regex(/^[A-Za-z0-9\._%+\-]+@[A-Za-z0-9\.\-]+\.[A-Za-z]{2,}$/, {
|
||||
message: 'Ведуть коректну e-mail адресу'
|
||||
})
|
||||
.max(320),
|
||||
address: z.coerce.string().trim(),
|
||||
notes: z.coerce.string().trim().max(1024).optional(),
|
||||
details: z.coerce.string().trim()
|
||||
})
|
||||
Reference in New Issue
Block a user