mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-24 10:51:13 -05:00
Fix: Enable TypeScript strict mode
This commit is contained in:
@@ -4,6 +4,7 @@ import { ImageAssignments } from '@/components/upload/EntityMultiImageUploader';
|
||||
import { uploadPendingImages } from './imageUploadHelper';
|
||||
import type { ProcessedImage } from './supabaseHelpers';
|
||||
import { extractChangedFields } from './submissionChangeDetection';
|
||||
import type { CompanyDatabaseRecord, TimelineEventDatabaseRecord } from '@/types/company-data';
|
||||
|
||||
/**
|
||||
* ═══════════════════════════════════════════════════════════════════
|
||||
@@ -723,7 +724,7 @@ export async function submitManufacturerUpdate(
|
||||
item_type: 'manufacturer',
|
||||
action_type: 'edit',
|
||||
item_data: {
|
||||
...extractChangedFields(data, existingCompany as any),
|
||||
...extractChangedFields(data, existingCompany as Partial<CompanyDatabaseRecord>),
|
||||
company_id: companyId, // Always include for relational integrity
|
||||
company_type: 'manufacturer', // Always include for entity type discrimination
|
||||
images: processedImages as unknown as Json
|
||||
@@ -831,7 +832,7 @@ export async function submitDesignerUpdate(
|
||||
item_type: 'designer',
|
||||
action_type: 'edit',
|
||||
item_data: {
|
||||
...extractChangedFields(data, existingCompany as any),
|
||||
...extractChangedFields(data, existingCompany as Partial<CompanyDatabaseRecord>),
|
||||
company_id: companyId, // Always include for relational integrity
|
||||
company_type: 'designer', // Always include for entity type discrimination
|
||||
images: processedImages as unknown as Json
|
||||
@@ -939,7 +940,7 @@ export async function submitOperatorUpdate(
|
||||
item_type: 'operator',
|
||||
action_type: 'edit',
|
||||
item_data: {
|
||||
...extractChangedFields(data, existingCompany as any),
|
||||
...extractChangedFields(data, existingCompany as Partial<CompanyDatabaseRecord>),
|
||||
company_id: companyId, // Always include for relational integrity
|
||||
company_type: 'operator', // Always include for entity type discrimination
|
||||
images: processedImages as unknown as Json
|
||||
@@ -1047,7 +1048,7 @@ export async function submitPropertyOwnerUpdate(
|
||||
item_type: 'property_owner',
|
||||
action_type: 'edit',
|
||||
item_data: {
|
||||
...extractChangedFields(data, existingCompany as any),
|
||||
...extractChangedFields(data, existingCompany as Partial<CompanyDatabaseRecord>),
|
||||
company_id: companyId, // Always include for relational integrity
|
||||
company_type: 'property_owner', // Always include for entity type discrimination
|
||||
images: processedImages as unknown as Json
|
||||
@@ -1128,7 +1129,7 @@ export async function submitTimelineEvent(
|
||||
p_user_id: userId,
|
||||
p_submission_type: 'milestone',
|
||||
p_content: content,
|
||||
p_items: items as any,
|
||||
p_items: items as unknown as Json[],
|
||||
});
|
||||
|
||||
if (error || !submissionId) {
|
||||
@@ -1169,9 +1170,9 @@ export async function submitTimelineEventUpdate(
|
||||
}
|
||||
|
||||
// Extract only changed fields from form data
|
||||
const changedFields = extractChangedFields(data, originalEvent as any);
|
||||
const changedFields = extractChangedFields(data, originalEvent as Partial<Record<string, unknown>>);
|
||||
|
||||
const itemData: Record<string, any> = {
|
||||
const itemData: Record<string, unknown> = {
|
||||
...changedFields,
|
||||
// Always include entity reference (for FK integrity)
|
||||
entity_type: originalEvent.entity_type,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { logger } from './logger';
|
||||
export type ErrorContext = {
|
||||
action: string;
|
||||
userId?: string;
|
||||
metadata?: Record<string, any>;
|
||||
metadata?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
export class AppError extends Error {
|
||||
@@ -66,11 +66,27 @@ export const handleInfo = (
|
||||
* Type-safe error message extraction utility
|
||||
* Use this instead of `error: any` in catch blocks
|
||||
*/
|
||||
export const getErrorMessage = (error: unknown): string => {
|
||||
if (error instanceof Error) return error.message;
|
||||
if (typeof error === 'string') return error;
|
||||
export function getErrorMessage(error: unknown): string {
|
||||
if (error instanceof Error) {
|
||||
return error.message;
|
||||
}
|
||||
if (typeof error === 'string') {
|
||||
return error;
|
||||
}
|
||||
if (error && typeof error === 'object' && 'message' in error) {
|
||||
return String(error.message);
|
||||
}
|
||||
return 'An unexpected error occurred';
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Type guard to check if error has a code property
|
||||
*/
|
||||
export function hasErrorCode(error: unknown): error is { code: string } {
|
||||
return (
|
||||
error !== null &&
|
||||
typeof error === 'object' &&
|
||||
'code' in error &&
|
||||
typeof (error as { code: unknown }).code === 'string'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -7,24 +7,22 @@
|
||||
|
||||
const isDev = import.meta.env.DEV;
|
||||
|
||||
type LogContext = {
|
||||
[key: string]: any;
|
||||
};
|
||||
type LogContext = Record<string, unknown>;
|
||||
|
||||
export const logger = {
|
||||
log: (...args: any[]) => {
|
||||
log: (...args: unknown[]): void => {
|
||||
if (isDev) console.log(...args);
|
||||
},
|
||||
error: (message: string, context?: LogContext) => {
|
||||
error: (message: string, context?: LogContext): void => {
|
||||
console.error(message, context); // Always log errors
|
||||
},
|
||||
warn: (...args: any[]) => {
|
||||
warn: (...args: unknown[]): void => {
|
||||
if (isDev) console.warn(...args);
|
||||
},
|
||||
info: (...args: any[]) => {
|
||||
info: (...args: unknown[]): void => {
|
||||
if (isDev) console.info(...args);
|
||||
},
|
||||
debug: (...args: any[]) => {
|
||||
debug: (...args: unknown[]): void => {
|
||||
if (isDev) console.debug(...args);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user