feat: Add user profile data to contact submissions

This commit is contained in:
gpt-engineer-app[bot]
2025-10-28 19:14:51 +00:00
parent 8300243bb2
commit 2ebb2eafec
4 changed files with 130 additions and 1 deletions

View File

@@ -124,9 +124,12 @@ const handler = async (req: Request): Promise<Response> => {
);
}
// Get user ID if authenticated
// Get user ID and profile if authenticated
const authHeader = req.headers.get('Authorization');
let userId: string | null = null;
let submitterUsername: string | null = null;
let submitterReputation: number | null = null;
let submitterProfileData: Record<string, unknown> | null = null;
if (authHeader) {
const supabaseClient = createClient(
@@ -137,6 +140,38 @@ const handler = async (req: Request): Promise<Response> => {
const { data: { user } } = await supabaseClient.auth.getUser();
userId = user?.id || null;
// Fetch user profile for enhanced context
if (userId) {
const { data: profile } = await supabase
.from('profiles')
.select('username, display_name, reputation_score, ride_count, coaster_count, park_count, review_count, created_at, avatar_url')
.eq('user_id', userId)
.single();
if (profile) {
submitterUsername = profile.username;
submitterReputation = profile.reputation_score || 0;
submitterProfileData = {
display_name: profile.display_name,
member_since: profile.created_at,
stats: {
rides: profile.ride_count || 0,
coasters: profile.coaster_count || 0,
parks: profile.park_count || 0,
reviews: profile.review_count || 0,
},
reputation: profile.reputation_score || 0,
avatar_url: profile.avatar_url
};
edgeLogger.info('Enhanced submission with user profile', {
requestId,
username: submitterUsername,
reputation: submitterReputation
});
}
}
}
// Insert contact submission (ticket number auto-generated by trigger)
@@ -144,6 +179,9 @@ const handler = async (req: Request): Promise<Response> => {
.from('contact_submissions')
.insert({
user_id: userId,
submitter_username: submitterUsername,
submitter_reputation: submitterReputation,
submitter_profile_data: submitterProfileData,
name: name.trim(),
email: email.trim().toLowerCase(),
subject: subject.trim(),