|
| 1 | +let auditLogs = []; |
| 2 | +let platformControls = { |
| 3 | + registrations: true, |
| 4 | + jobPostings: true |
| 5 | +}; |
| 6 | + |
1 | 7 | export async function getAdminMetrics() { |
2 | 8 | return { |
3 | 9 | openJobs: 42, |
4 | 10 | activeFreelancers: 185, |
5 | 11 | flaggedAccounts: 3, |
6 | | - monthlyVolume: 128900 |
| 12 | + monthlyVolume: 128900, |
| 13 | + trustScoreAverage: 8.4 |
7 | 14 | }; |
8 | 15 | } |
| 16 | + |
| 17 | +export async function listUsers({ page, limit, search, role, status }) { |
| 18 | + // Mock user data |
| 19 | + const users = Array.from({ length: 50 }, (_, i) => ({ |
| 20 | + id: `usr_${i}`, |
| 21 | + email: `user${i}@example.com`, |
| 22 | + role: i % 2 === 0 ? "freelancer" : "client", |
| 23 | + status: i % 10 === 0 ? "suspended" : "active", |
| 24 | + joinedAt: new Date(Date.now() - i * 86400000).toISOString() |
| 25 | + })); |
| 26 | + |
| 27 | + let filtered = users; |
| 28 | + if (role) filtered = filtered.filter(u => u.role === role); |
| 29 | + if (status) filtered = filtered.filter(u => u.status === status); |
| 30 | + if (search) filtered = filtered.filter(u => u.email.includes(search)); |
| 31 | + |
| 32 | + const start = (page - 1) * limit; |
| 33 | + return { |
| 34 | + data: filtered.slice(start, start + limit), |
| 35 | + total: filtered.length, |
| 36 | + page, |
| 37 | + totalPages: Math.ceil(filtered.length / limit) |
| 38 | + }; |
| 39 | +} |
| 40 | + |
| 41 | +export async function setUserStatus(id, status, reason, adminId) { |
| 42 | + auditLogs.push({ |
| 43 | + timestamp: new Date().toISOString(), |
| 44 | + adminId, |
| 45 | + action: `USER_${status.toUpperCase()}`, |
| 46 | + targetId: id, |
| 47 | + metadata: { reason } |
| 48 | + }); |
| 49 | + return { id, status, updated: true }; |
| 50 | +} |
| 51 | + |
| 52 | +export async function getFlaggedContent() { |
| 53 | + return [ |
| 54 | + { id: "job_1", type: "job", title: "Suspicious Crypto Job", flaggedBy: "system", reason: "Spam keywords" }, |
| 55 | + { id: "job_2", type: "job", title: "Direct Payment Request", flaggedBy: "user_123", reason: "Terms violation" } |
| 56 | + ]; |
| 57 | +} |
| 58 | + |
| 59 | +export async function processModeration(id, action, reason, adminId) { |
| 60 | + auditLogs.push({ |
| 61 | + timestamp: new Date().toISOString(), |
| 62 | + adminId, |
| 63 | + action: `MODERATION_${action.toUpperCase()}`, |
| 64 | + targetId: id, |
| 65 | + metadata: { reason } |
| 66 | + }); |
| 67 | + return { id, action, status: "processed" }; |
| 68 | +} |
| 69 | + |
| 70 | +export async function listDisputes() { |
| 71 | + return [ |
| 72 | + { id: "disp_1", client: "client_1", freelancer: "free_1", amount: 500, status: "open", reason: "Non-delivery" }, |
| 73 | + { id: "disp_2", client: "client_2", freelancer: "free_2", amount: 1200, status: "under_review", reason: "Quality issue" } |
| 74 | + ]; |
| 75 | +} |
| 76 | + |
| 77 | +export async function closeDispute(id, { winner, resolution, refundAmount }, adminId) { |
| 78 | + auditLogs.push({ |
| 79 | + timestamp: new Date().toISOString(), |
| 80 | + adminId, |
| 81 | + action: "DISPUTE_RESOLVED", |
| 82 | + targetId: id, |
| 83 | + metadata: { winner, resolution, refundAmount } |
| 84 | + }); |
| 85 | + return { id, status: "resolved", winner }; |
| 86 | +} |
| 87 | + |
| 88 | +export async function fetchAuditLogs() { |
| 89 | + return auditLogs.sort((a, b) => new Date(b.timestamp) - new Date(a.timestamp)); |
| 90 | +} |
| 91 | + |
| 92 | +export async function setPlatformControl(type, enabled, adminId) { |
| 93 | + platformControls[type] = enabled; |
| 94 | + auditLogs.push({ |
| 95 | + timestamp: new Date().toISOString(), |
| 96 | + adminId, |
| 97 | + action: "PLATFORM_CONTROL_UPDATE", |
| 98 | + metadata: { type, enabled } |
| 99 | + }); |
| 100 | + return { type, enabled }; |
| 101 | +} |
0 commit comments