|
|
|
@@ -1,11 +1,9 @@ |
|
|
|
import type { Card, CardType } from '@/types'; |
|
|
|
import type { Card, CardType, Portal } from '@/types'; |
|
|
|
import { TEXT_LIMITS } from '@/lib/config'; |
|
|
|
|
|
|
|
export const CARD_LIMITS = { |
|
|
|
title: 200, |
|
|
|
shortDescription: 500, |
|
|
|
fullContent: 20000, |
|
|
|
actionUrl: 2000, |
|
|
|
} as const; |
|
|
|
// Re-export per retro-compatibilità con il codice che importa CARD_LIMITS. |
|
|
|
export const CARD_LIMITS = TEXT_LIMITS.card; |
|
|
|
export const PORTAL_LIMITS = TEXT_LIMITS.portal; |
|
|
|
|
|
|
|
const VALID_CARD_TYPES: readonly CardType[] = [ |
|
|
|
'INFO_PAGE', |
|
|
|
@@ -77,3 +75,25 @@ export function validateCard(card: Partial<Card>): ValidationResult { |
|
|
|
|
|
|
|
return { valid: errors.length === 0, errors }; |
|
|
|
} |
|
|
|
|
|
|
|
export function validatePortal(portal: Partial<Portal>): ValidationResult { |
|
|
|
const errors: ValidationError[] = []; |
|
|
|
|
|
|
|
if (portal.title !== undefined) { |
|
|
|
if (typeof portal.title !== 'string') { |
|
|
|
errors.push({ field: 'title', message: 'Tipo non valido' }); |
|
|
|
} else if (portal.title.length > PORTAL_LIMITS.title) { |
|
|
|
errors.push({ field: 'title', message: 'Titolo portale troppo lungo', limit: PORTAL_LIMITS.title, actual: portal.title.length }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (portal.welcomeText !== undefined) { |
|
|
|
if (typeof portal.welcomeText !== 'string') { |
|
|
|
errors.push({ field: 'welcomeText', message: 'Tipo non valido' }); |
|
|
|
} else if (portal.welcomeText.length > PORTAL_LIMITS.welcomeText) { |
|
|
|
errors.push({ field: 'welcomeText', message: 'Testo di benvenuto troppo lungo', limit: PORTAL_LIMITS.welcomeText, actual: portal.welcomeText.length }); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return { valid: errors.length === 0, errors }; |
|
|
|
} |