mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-25 14:25:02 +00:00
code: validate,page,dbal (2 files)
This commit is contained in:
@@ -2,6 +2,7 @@ import type { PageView } from '../types'
|
||||
import { isValidLevel } from './is-valid-level'
|
||||
import { isValidSlug } from './is-valid-slug'
|
||||
import { isValidTitle } from './is-valid-title'
|
||||
import { isPlainObject } from './is-plain-object'
|
||||
|
||||
/**
|
||||
* Validation rules for PageView entity
|
||||
@@ -12,19 +13,35 @@ export function validatePageCreate(data: Partial<PageView>): string[] {
|
||||
if (!data.slug) {
|
||||
errors.push('Slug is required')
|
||||
} else if (!isValidSlug(data.slug)) {
|
||||
errors.push('Invalid slug format (lowercase alphanumeric with hyphens, 1-100 chars)')
|
||||
errors.push('Invalid slug format (lowercase alphanumeric, hyphen, slash, 1-255 chars)')
|
||||
}
|
||||
|
||||
if (!data.title) {
|
||||
errors.push('Title is required')
|
||||
} else if (!isValidTitle(data.title)) {
|
||||
errors.push('Invalid title (must be 1-200 characters)')
|
||||
errors.push('Invalid title (must be 1-255 characters)')
|
||||
}
|
||||
|
||||
if (data.level === undefined) {
|
||||
errors.push('Level is required')
|
||||
} else if (!isValidLevel(data.level)) {
|
||||
errors.push('Invalid level (must be 0-5)')
|
||||
errors.push('Invalid level (must be 1-5)')
|
||||
}
|
||||
|
||||
if (data.layout === undefined) {
|
||||
errors.push('Layout is required')
|
||||
} else if (!isPlainObject(data.layout)) {
|
||||
errors.push('Layout must be an object')
|
||||
}
|
||||
|
||||
if (data.isActive === undefined) {
|
||||
errors.push('isActive is required')
|
||||
} else if (typeof data.isActive !== 'boolean') {
|
||||
errors.push('isActive must be a boolean')
|
||||
}
|
||||
|
||||
if (data.description !== undefined && typeof data.description !== 'string') {
|
||||
errors.push('Description must be a string')
|
||||
}
|
||||
|
||||
return errors
|
||||
|
||||
@@ -2,20 +2,33 @@ import type { PageView } from '../types'
|
||||
import { isValidLevel } from './is-valid-level'
|
||||
import { isValidSlug } from './is-valid-slug'
|
||||
import { isValidTitle } from './is-valid-title'
|
||||
import { isPlainObject } from './is-plain-object'
|
||||
|
||||
export function validatePageUpdate(data: Partial<PageView>): string[] {
|
||||
const errors: string[] = []
|
||||
|
||||
if (data.slug !== undefined && !isValidSlug(data.slug)) {
|
||||
errors.push('Invalid slug format')
|
||||
errors.push('Invalid slug format (lowercase alphanumeric, hyphen, slash, 1-255 chars)')
|
||||
}
|
||||
|
||||
if (data.title !== undefined && !isValidTitle(data.title)) {
|
||||
errors.push('Invalid title (must be 1-200 characters)')
|
||||
errors.push('Invalid title (must be 1-255 characters)')
|
||||
}
|
||||
|
||||
if (data.level !== undefined && !isValidLevel(data.level)) {
|
||||
errors.push('Invalid level (must be 0-5)')
|
||||
errors.push('Invalid level (must be 1-5)')
|
||||
}
|
||||
|
||||
if (data.layout !== undefined && !isPlainObject(data.layout)) {
|
||||
errors.push('Layout must be an object')
|
||||
}
|
||||
|
||||
if (data.isActive !== undefined && typeof data.isActive !== 'boolean') {
|
||||
errors.push('isActive must be a boolean')
|
||||
}
|
||||
|
||||
if (data.description !== undefined && typeof data.description !== 'string') {
|
||||
errors.push('Description must be a string')
|
||||
}
|
||||
|
||||
return errors
|
||||
|
||||
Reference in New Issue
Block a user