mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-20 11:51:14 -05:00
feat: Implement full type safety plan
This commit is contained in:
77
supabase/functions/_shared/types.ts
Normal file
77
supabase/functions/_shared/types.ts
Normal file
@@ -0,0 +1,77 @@
|
||||
/**
|
||||
* Shared type definitions for edge functions
|
||||
* Provides type safety across all backend operations
|
||||
*/
|
||||
|
||||
export interface SubmissionUpdateData {
|
||||
status?: 'approved' | 'rejected' | 'pending';
|
||||
reviewer_id?: string;
|
||||
reviewed_at?: string;
|
||||
reviewer_notes?: string;
|
||||
}
|
||||
|
||||
export interface PhotoSubmissionUpdateData {
|
||||
status?: 'approved' | 'rejected' | 'pending';
|
||||
reviewed_by?: string;
|
||||
reviewed_at?: string;
|
||||
reviewer_notes?: string;
|
||||
}
|
||||
|
||||
export interface ReviewUpdateData {
|
||||
is_approved?: boolean;
|
||||
approved_by?: string;
|
||||
approved_at?: string;
|
||||
reviewer_notes?: string;
|
||||
}
|
||||
|
||||
export interface EntityData {
|
||||
id?: string;
|
||||
name?: string;
|
||||
slug?: string;
|
||||
description?: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface LocationData {
|
||||
country?: string;
|
||||
state_province?: string;
|
||||
city?: string;
|
||||
latitude?: number;
|
||||
longitude?: number;
|
||||
}
|
||||
|
||||
export interface SubscriberData {
|
||||
subscriberId: string;
|
||||
email?: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
phone?: string;
|
||||
avatar?: string;
|
||||
data?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface NotificationPayload {
|
||||
workflowId: string;
|
||||
subscriberId?: string;
|
||||
topicKey?: string;
|
||||
payload: Record<string, unknown>;
|
||||
overrides?: Record<string, unknown>;
|
||||
}
|
||||
|
||||
export interface ApprovalRequest {
|
||||
submissionId: string;
|
||||
itemIds: string[];
|
||||
action: 'approve' | 'reject';
|
||||
notes?: string;
|
||||
}
|
||||
|
||||
export interface ValidationResult {
|
||||
valid: boolean;
|
||||
errors: string[];
|
||||
}
|
||||
|
||||
export interface StrictValidationResult {
|
||||
valid: boolean;
|
||||
blockingErrors: string[];
|
||||
warnings: string[];
|
||||
}
|
||||
@@ -22,7 +22,13 @@ serve(async (req) => {
|
||||
secretKey: novuApiKey
|
||||
});
|
||||
|
||||
const { workflowId, subscriberId, topicKey, payload, overrides } = await req.json();
|
||||
const { workflowId, subscriberId, topicKey, payload, overrides } = await req.json() as {
|
||||
workflowId: string;
|
||||
subscriberId?: string;
|
||||
topicKey?: string;
|
||||
payload: Record<string, unknown>;
|
||||
overrides?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
// Support both individual subscribers and topics
|
||||
if (!subscriberId && !topicKey) {
|
||||
@@ -31,7 +37,7 @@ serve(async (req) => {
|
||||
|
||||
const recipient = subscriberId
|
||||
? { subscriberId }
|
||||
: { topicKey };
|
||||
: { topicKey: topicKey! };
|
||||
|
||||
console.log('Triggering notification:', { workflowId, recipient });
|
||||
|
||||
@@ -54,13 +60,14 @@ serve(async (req) => {
|
||||
status: 200,
|
||||
}
|
||||
);
|
||||
} catch (error: any) {
|
||||
console.error('Error triggering notification:', error);
|
||||
} catch (error: unknown) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
||||
console.error('Error triggering notification:', errorMessage);
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: false,
|
||||
error: error.message,
|
||||
error: errorMessage,
|
||||
}),
|
||||
{
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
||||
|
||||
@@ -22,7 +22,15 @@ serve(async (req) => {
|
||||
secretKey: novuApiKey
|
||||
});
|
||||
|
||||
const { subscriberId, email, firstName, lastName, phone, avatar, data } = await req.json();
|
||||
const { subscriberId, email, firstName, lastName, phone, avatar, data } = await req.json() as {
|
||||
subscriberId: string;
|
||||
email?: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
phone?: string;
|
||||
avatar?: string;
|
||||
data?: Record<string, unknown>;
|
||||
};
|
||||
|
||||
console.log('Updating Novu subscriber:', { subscriberId, email, firstName });
|
||||
|
||||
@@ -47,13 +55,14 @@ serve(async (req) => {
|
||||
status: 200,
|
||||
}
|
||||
);
|
||||
} catch (error: any) {
|
||||
console.error('Error updating Novu subscriber:', error);
|
||||
} catch (error: unknown) {
|
||||
const errorMessage = error instanceof Error ? error.message : 'Unknown error occurred';
|
||||
console.error('Error updating Novu subscriber:', errorMessage);
|
||||
|
||||
return new Response(
|
||||
JSON.stringify({
|
||||
success: false,
|
||||
error: error.message,
|
||||
error: errorMessage,
|
||||
}),
|
||||
{
|
||||
headers: { ...corsHeaders, 'Content-Type': 'application/json' },
|
||||
|
||||
Reference in New Issue
Block a user