mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 08:11:13 -05:00
Refactor: Implement entity type safety plan
This commit is contained in:
@@ -7,6 +7,7 @@ export interface CompanyFormData {
|
||||
name: string;
|
||||
slug: string;
|
||||
description?: string;
|
||||
company_type: 'manufacturer' | 'designer' | 'operator' | 'property_owner';
|
||||
person_type: 'company' | 'individual' | 'firm' | 'organization';
|
||||
website_url?: string;
|
||||
founded_year?: number;
|
||||
|
||||
@@ -341,7 +341,8 @@ export default function DesignerDetail() {
|
||||
name: designer.name,
|
||||
slug: designer.slug,
|
||||
description: designer.description,
|
||||
person_type: designer.person_type as any,
|
||||
company_type: 'designer',
|
||||
person_type: designer.person_type,
|
||||
website_url: designer.website_url,
|
||||
founded_year: designer.founded_year,
|
||||
headquarters_location: designer.headquarters_location,
|
||||
|
||||
@@ -69,7 +69,7 @@ export default function DesignerRides() {
|
||||
query = query.order('max_speed_kmh', { ascending: false, nullsFirst: false });
|
||||
break;
|
||||
case 'height':
|
||||
query = query.order('max_height_meters', { ascending: false, nullsFirst: false });
|
||||
query = query.order('height_meters', { ascending: false, nullsFirst: false });
|
||||
break;
|
||||
case 'reviews':
|
||||
query = query.order('review_count', { ascending: false });
|
||||
@@ -102,10 +102,6 @@ export default function DesignerRides() {
|
||||
|
||||
const handleCreateSubmit = async (data: any) => {
|
||||
try {
|
||||
if (!user || !designer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!designer) {
|
||||
toast({
|
||||
title: "Error",
|
||||
@@ -130,10 +126,11 @@ export default function DesignerRides() {
|
||||
|
||||
setIsCreateModalOpen(false);
|
||||
fetchData();
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Failed to submit ride.";
|
||||
toast({
|
||||
title: "Error",
|
||||
description: error.message || "Failed to submit ride.",
|
||||
description: message,
|
||||
variant: "destructive"
|
||||
});
|
||||
}
|
||||
|
||||
@@ -375,7 +375,8 @@ export default function ManufacturerDetail() {
|
||||
name: manufacturer.name,
|
||||
slug: manufacturer.slug,
|
||||
description: manufacturer.description,
|
||||
person_type: manufacturer.person_type as any,
|
||||
company_type: 'manufacturer',
|
||||
person_type: manufacturer.person_type,
|
||||
website_url: manufacturer.website_url,
|
||||
founded_year: manufacturer.founded_year,
|
||||
headquarters_location: manufacturer.headquarters_location,
|
||||
|
||||
@@ -22,7 +22,7 @@ export default function ManufacturerModels() {
|
||||
const { user } = useAuth();
|
||||
const { requireAuth } = useAuthModal();
|
||||
const [manufacturer, setManufacturer] = useState<Company | null>(null);
|
||||
const [models, setModels] = useState<RideModel[]>([]);
|
||||
const [models, setModels] = useState<RideModelWithCount[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [sortBy, setSortBy] = useState('name');
|
||||
@@ -68,12 +68,12 @@ export default function ManufacturerModels() {
|
||||
if (modelsError) throw modelsError;
|
||||
|
||||
// Transform data to include ride count
|
||||
const modelsWithCounts = (modelsData || []).map(model => ({
|
||||
const modelsWithCounts: RideModelWithCount[] = (modelsData || []).map(model => ({
|
||||
...model,
|
||||
ride_count: Array.isArray(model.rides) ? model.rides[0]?.count || 0 : 0
|
||||
}));
|
||||
|
||||
setModels(modelsWithCounts as RideModel[]);
|
||||
setModels(modelsWithCounts);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error fetching data:', error);
|
||||
@@ -95,10 +95,6 @@ export default function ManufacturerModels() {
|
||||
|
||||
const handleCreateSubmit = async (data: any) => {
|
||||
try {
|
||||
if (!user || !manufacturer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!manufacturer) {
|
||||
toast({
|
||||
title: "Error",
|
||||
@@ -123,10 +119,11 @@ export default function ManufacturerModels() {
|
||||
|
||||
setIsCreateModalOpen(false);
|
||||
fetchData();
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Failed to submit ride model.";
|
||||
toast({
|
||||
title: "Error",
|
||||
description: error.message || "Failed to submit ride model.",
|
||||
description: message,
|
||||
variant: "destructive"
|
||||
});
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ export default function ManufacturerRides() {
|
||||
query = query.order('max_speed_kmh', { ascending: false, nullsFirst: false });
|
||||
break;
|
||||
case 'height':
|
||||
query = query.order('max_height_meters', { ascending: false, nullsFirst: false });
|
||||
query = query.order('height_meters', { ascending: false, nullsFirst: false });
|
||||
break;
|
||||
case 'reviews':
|
||||
query = query.order('review_count', { ascending: false });
|
||||
@@ -102,10 +102,6 @@ export default function ManufacturerRides() {
|
||||
|
||||
const handleCreateSubmit = async (data: any) => {
|
||||
try {
|
||||
if (!user || !manufacturer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!manufacturer) {
|
||||
toast({
|
||||
title: "Error",
|
||||
@@ -130,10 +126,11 @@ export default function ManufacturerRides() {
|
||||
|
||||
setIsCreateModalOpen(false);
|
||||
fetchData();
|
||||
} catch (error: any) {
|
||||
} catch (error) {
|
||||
const message = error instanceof Error ? error.message : "Failed to submit ride.";
|
||||
toast({
|
||||
title: "Error",
|
||||
description: error.message || "Failed to submit ride.",
|
||||
description: message,
|
||||
variant: "destructive"
|
||||
});
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ export default function OperatorDetail() {
|
||||
const { slug } = useParams<{ slug: string }>();
|
||||
const navigate = useNavigate();
|
||||
const [operator, setOperator] = useState<Company | null>(null);
|
||||
const [parks, setParks] = useState<any[]>([]);
|
||||
const [parks, setParks] = useState<Park[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [parksLoading, setParksLoading] = useState(true);
|
||||
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
|
||||
@@ -427,7 +427,8 @@ export default function OperatorDetail() {
|
||||
name: operator.name,
|
||||
slug: operator.slug,
|
||||
description: operator.description,
|
||||
person_type: operator.person_type as any,
|
||||
company_type: 'operator',
|
||||
person_type: operator.person_type,
|
||||
website_url: operator.website_url,
|
||||
founded_year: operator.founded_year,
|
||||
headquarters_location: operator.headquarters_location,
|
||||
|
||||
@@ -26,7 +26,7 @@ export default function PropertyOwnerDetail() {
|
||||
const { slug } = useParams<{ slug: string }>();
|
||||
const navigate = useNavigate();
|
||||
const [owner, setOwner] = useState<Company | null>(null);
|
||||
const [parks, setParks] = useState<any[]>([]);
|
||||
const [parks, setParks] = useState<Park[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [parksLoading, setParksLoading] = useState(true);
|
||||
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
|
||||
@@ -427,7 +427,8 @@ export default function PropertyOwnerDetail() {
|
||||
name: owner.name,
|
||||
slug: owner.slug,
|
||||
description: owner.description,
|
||||
person_type: owner.person_type as any,
|
||||
company_type: 'property_owner',
|
||||
person_type: owner.person_type,
|
||||
website_url: owner.website_url,
|
||||
founded_year: owner.founded_year,
|
||||
headquarters_location: owner.headquarters_location,
|
||||
|
||||
@@ -16,7 +16,7 @@ export interface Company {
|
||||
slug: string;
|
||||
description?: string;
|
||||
company_type: string; // Allow any string from database
|
||||
person_type: string; // 'company', 'individual', 'firm', 'organization'
|
||||
person_type: 'company' | 'individual' | 'firm' | 'organization';
|
||||
website_url?: string;
|
||||
founded_year?: number; // Legacy field
|
||||
founded_date?: string;
|
||||
|
||||
Reference in New Issue
Block a user