aethex-forge/api/nexus-core/talent-profiles.ts
sirpiglr e60e71476f Add core architecture, API endpoints, and UI components for NEXUS
Introduces NEXUS Core architecture documentation, new API endpoints for escrow, payroll, talent profiles, time logs, and UI components for financial dashboards and compliance tracking.

Replit-Commit-Author: Agent
Replit-Commit-Session-Id: 9203795e-937a-4306-b81d-b4d5c78c240e
Replit-Commit-Checkpoint-Type: intermediate_checkpoint
Replit-Commit-Event-Id: e82c1588-4c11-4961-b289-6ab581ed9691
Replit-Commit-Screenshot-Url: https://storage.googleapis.com/screenshot-production-us-central1/7c94b7a0-29c7-4f2e-94ef-44b2153872b7/9203795e-937a-4306-b81d-b4d5c78c240e/aPpJgbb
Replit-Helium-Checkpoint-Created: true
2025-12-13 03:01:54 +00:00

84 lines
2.5 KiB
TypeScript

import type { VercelRequest, VercelResponse } from "@vercel/node";
import { getAdminClient } from "../_supabase";
export default async function handler(req: VercelRequest, res: VercelResponse) {
const supabase = getAdminClient();
const authHeader = req.headers.authorization;
if (!authHeader?.startsWith('Bearer ')) {
return res.status(401).json({ error: 'Unauthorized' });
}
const token = authHeader.split(' ')[1];
const { data: { user }, error: authError } = await supabase.auth.getUser(token);
if (authError || !user) {
return res.status(401).json({ error: 'Invalid token' });
}
if (req.method === 'GET') {
const { data, error } = await supabase
.from('nexus_talent_profiles')
.select('*')
.eq('user_id', user.id)
.single();
if (error && error.code !== 'PGRST116') {
return res.status(500).json({ error: error.message });
}
return res.status(200).json({ data });
}
if (req.method === 'POST') {
const body = req.body;
const { data, error } = await supabase
.from('nexus_talent_profiles')
.upsert({
user_id: user.id,
legal_first_name: body.legal_first_name,
legal_last_name: body.legal_last_name,
tax_classification: body.tax_classification,
residency_state: body.residency_state,
residency_country: body.residency_country || 'US',
address_city: body.address_city,
address_state: body.address_state,
address_zip: body.address_zip,
updated_at: new Date().toISOString()
}, { onConflict: 'user_id' })
.select()
.single();
if (error) {
return res.status(500).json({ error: error.message });
}
await supabase.from('nexus_compliance_events').insert({
entity_type: 'talent',
entity_id: data.id,
event_type: 'profile_updated',
event_category: 'data_change',
actor_id: user.id,
actor_role: 'talent',
realm_context: 'nexus',
description: 'Talent profile updated',
payload: { fields_updated: Object.keys(body) }
});
return res.status(200).json({ data });
}
if (req.method === 'GET' && req.query.action === 'compliance-summary') {
const { data, error } = await supabase
.rpc('get_talent_compliance_summary', { p_user_id: user.id });
if (error) {
return res.status(500).json({ error: error.message });
}
return res.status(200).json({ data });
}
return res.status(405).json({ error: 'Method not allowed' });
}