Add staff users listing endpoint
cgen-b486b439363240e992013fbe2cb1701c
This commit is contained in:
parent
0b903161ce
commit
16de77fb35
1 changed files with 24 additions and 0 deletions
|
|
@ -1180,6 +1180,30 @@ export function createServer() {
|
|||
}
|
||||
});
|
||||
|
||||
// Staff: users search/listing
|
||||
app.get("/api/staff/users", async (req, res) => {
|
||||
const limit = Math.max(1, Math.min(50, Number(req.query.limit) || 20));
|
||||
const q = String(req.query.q || "").trim().toLowerCase();
|
||||
try {
|
||||
const { data, error } = await adminSupabase
|
||||
.from("user_profiles")
|
||||
.select("id, username, full_name, avatar_url, user_type, created_at, updated_at")
|
||||
.order("created_at", { ascending: false })
|
||||
.limit(limit);
|
||||
if (error) return res.status(500).json({ error: error.message });
|
||||
let rows = (data || []) as any[];
|
||||
if (q) {
|
||||
rows = rows.filter((r) => {
|
||||
const name = String(r.full_name || r.username || "").toLowerCase();
|
||||
return name.includes(q);
|
||||
});
|
||||
}
|
||||
return res.json(rows);
|
||||
} catch (e: any) {
|
||||
return res.status(500).json({ error: e?.message || String(e) });
|
||||
}
|
||||
});
|
||||
|
||||
// Mentorship API
|
||||
app.get("/api/mentors", async (req, res) => {
|
||||
const limit = Math.max(1, Math.min(50, Number(req.query.limit) || 20));
|
||||
|
|
|
|||
Loading…
Reference in a new issue