mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-22 11:11:14 -05:00
Fix validation for edits
This commit is contained in:
@@ -20,7 +20,8 @@ export interface StrictValidationResult {
|
||||
*/
|
||||
export function validateEntityDataStrict(
|
||||
entityType: string,
|
||||
data: any
|
||||
data: any,
|
||||
originalData?: any
|
||||
): StrictValidationResult {
|
||||
const result: StrictValidationResult = {
|
||||
valid: true,
|
||||
@@ -78,7 +79,10 @@ export function validateEntityDataStrict(
|
||||
if (!data.status) {
|
||||
result.blockingErrors.push('Status is required');
|
||||
}
|
||||
if (data.location_id === null || data.location_id === undefined) {
|
||||
// For edits, check if location exists in either new or original data
|
||||
const hasLocation = data.location_id !== null && data.location_id !== undefined;
|
||||
const hadLocation = originalData?.location_id !== null && originalData?.location_id !== undefined;
|
||||
if (!hasLocation && !hadLocation) {
|
||||
result.blockingErrors.push('Location is required for parks');
|
||||
}
|
||||
if (data.opening_date && data.closing_date) {
|
||||
@@ -97,7 +101,10 @@ export function validateEntityDataStrict(
|
||||
if (!data.status) {
|
||||
result.blockingErrors.push('Status is required');
|
||||
}
|
||||
if (data.park_id === null || data.park_id === undefined) {
|
||||
// For edits, check if park exists in either new or original data
|
||||
const hasPark = data.park_id !== null && data.park_id !== undefined;
|
||||
const hadPark = originalData?.park_id !== null && originalData?.park_id !== undefined;
|
||||
if (!hasPark && !hadPark) {
|
||||
result.blockingErrors.push('Park is required for rides');
|
||||
}
|
||||
if (data.max_speed_kmh && (data.max_speed_kmh < 0 || data.max_speed_kmh > 300)) {
|
||||
|
||||
Reference in New Issue
Block a user