Replaces direct Supabase client instantiation with a unified authentication and authorization helper, introducing role-based access control to sensitive endpoints like escrow and payroll, and standardizing compliance event logging. Replit-Commit-Author: Agent Replit-Commit-Session-Id: 9203795e-937a-4306-b81d-b4d5c78c240e Replit-Commit-Checkpoint-Type: intermediate_checkpoint Replit-Commit-Event-Id: 5eb35c62-c5ab-4c7e-9552-8dc89efa29f3 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
69 lines
1.9 KiB
TypeScript
69 lines
1.9 KiB
TypeScript
import type { VercelRequest, VercelResponse } from "@vercel/node";
|
|
import { authenticateRequest, requireAuth, logComplianceEvent } from "../_auth";
|
|
|
|
export default async function handler(req: VercelRequest, res: VercelResponse) {
|
|
if (req.method !== 'GET') {
|
|
return res.status(405).json({ error: 'Method not allowed' });
|
|
}
|
|
|
|
const auth = await authenticateRequest(req);
|
|
if (!requireAuth(auth, res)) return;
|
|
|
|
const { userClient, adminClient, user } = auth;
|
|
|
|
const { category, skills, experience, limit = 20, offset = 0 } = req.query;
|
|
|
|
const { data, error } = await userClient
|
|
.from('foundation_gig_radar')
|
|
.select('*')
|
|
.order('published_at', { ascending: false })
|
|
.range(Number(offset), Number(offset) + Number(limit) - 1);
|
|
|
|
if (error) {
|
|
return res.status(500).json({ error: error.message });
|
|
}
|
|
|
|
let filteredData = data || [];
|
|
|
|
if (category) {
|
|
filteredData = filteredData.filter(d => d.category === category);
|
|
}
|
|
|
|
if (skills) {
|
|
const skillsArray = (skills as string).split(',');
|
|
filteredData = filteredData.filter(d =>
|
|
d.required_skills.some((s: string) => skillsArray.includes(s))
|
|
);
|
|
}
|
|
|
|
if (experience) {
|
|
filteredData = filteredData.filter(d => d.required_experience === experience);
|
|
}
|
|
|
|
await logComplianceEvent(adminClient, {
|
|
entity_type: 'gig_radar',
|
|
entity_id: user.id,
|
|
event_type: 'gig_radar_accessed',
|
|
event_category: 'access',
|
|
actor_id: user.id,
|
|
actor_role: 'user',
|
|
realm_context: 'foundation',
|
|
description: 'Foundation user accessed Gig Radar',
|
|
payload: {
|
|
filters: { category, skills, experience },
|
|
results_count: filteredData.length
|
|
},
|
|
sensitive_data_accessed: false,
|
|
cross_entity_access: true,
|
|
legal_entity: 'non_profit'
|
|
}, req);
|
|
|
|
return res.status(200).json({
|
|
data: filteredData,
|
|
meta: {
|
|
total: filteredData.length,
|
|
limit: Number(limit),
|
|
offset: Number(offset)
|
|
}
|
|
});
|
|
}
|