|
| 1 | +import { faker } from '@faker-js/faker'; |
| 2 | +import { Request, Response, Router } from 'express'; |
| 3 | + |
| 4 | +const router = Router(); |
| 5 | + |
| 6 | +// Helper to randomly return valid or empty data |
| 7 | +const maybe = <T>(value: T, probability = 0.7) => |
| 8 | + Math.random() < probability ? value : null; |
| 9 | + |
| 10 | +router.get('/api/v2/profile/resolve/email', (req: Request, res: Response) => { |
| 11 | + const { email } = req.query; |
| 12 | + // Validation: Ensure email is provided |
| 13 | + if (!email) { |
| 14 | + return res.status(400).json({ |
| 15 | + code: '400', |
| 16 | + error: 'Email parameter is required for reverse lookup' |
| 17 | + }); |
| 18 | + } |
| 19 | + |
| 20 | + try { |
| 21 | + const fakeProfile = { |
| 22 | + city: maybe(faker.location.city(), 0.8), |
| 23 | + full_name: maybe(faker.person.fullName(), 0.9), |
| 24 | + first_name: maybe(faker.person.firstName(), 0.85), |
| 25 | + last_name: maybe(faker.person.lastName(), 0.85), |
| 26 | + state: maybe(faker.location.state(), 0.6), |
| 27 | + country: maybe(faker.location.countryCode('alpha-2'), 0.7), |
| 28 | + country_full_name: maybe(faker.location.country(), 0.7), |
| 29 | + languages: maybe([faker.lorem.word(), faker.lorem.word()], 0.6), |
| 30 | + occupation: maybe(faker.person.jobTitle(), 0.75), |
| 31 | + profile_pic_url: maybe(faker.image.avatar(), 0.8), |
| 32 | + public_identifier: faker.string.alphanumeric(10), |
| 33 | + extra: { |
| 34 | + github_profile_id: maybe(faker.internet.userName(), 0.5), |
| 35 | + facebook_profile_id: maybe(faker.internet.userName(), 0.5), |
| 36 | + twitter_profile_id: maybe(faker.internet.userName(), 0.5), |
| 37 | + website: maybe(faker.internet.url(), 0.5) |
| 38 | + }, |
| 39 | + experiences: Array.from({ length: 2 }).map(() => ({ |
| 40 | + starts_at: { |
| 41 | + day: faker.number.int({ min: 1, max: 28 }), |
| 42 | + month: faker.number.int({ min: 1, max: 12 }), |
| 43 | + year: faker.number.int({ min: 2000, max: 2023 }) |
| 44 | + }, |
| 45 | + ends_at: { |
| 46 | + day: maybe(faker.number.int({ min: 1, max: 28 }), 0.7), |
| 47 | + month: maybe(faker.number.int({ min: 1, max: 12 }), 0.7), |
| 48 | + year: maybe(faker.number.int({ min: 2000, max: 2024 }), 0.7) |
| 49 | + }, |
| 50 | + company: maybe(faker.company.name(), 0.9), |
| 51 | + company_linkedin_profile_url: maybe(faker.internet.url(), 0.4), |
| 52 | + company_facebook_profile_url: maybe(faker.internet.url(), 0.4), |
| 53 | + title: maybe(faker.person.jobTitle(), 0.85), |
| 54 | + description: maybe(faker.lorem.paragraph(), 0.6), |
| 55 | + location: maybe(faker.location.city(), 0.6), |
| 56 | + logo_url: maybe(faker.image.avatar(), 0.7) |
| 57 | + })) |
| 58 | + }; |
| 59 | + |
| 60 | + // Respond with the fake data |
| 61 | + return res.status(200).json({ |
| 62 | + email, |
| 63 | + profile: fakeProfile, |
| 64 | + last_updated: faker.date.recent().toISOString(), |
| 65 | + similarity_score: parseFloat( |
| 66 | + faker.number.float({ min: 0.5, max: 1 }).toFixed(2) |
| 67 | + ), |
| 68 | + linkedin_profile_url: maybe(faker.internet.url(), 0.7), |
| 69 | + facebook_profile_url: maybe(faker.internet.url(), 0.7), |
| 70 | + twitter_profile_url: maybe(faker.internet.url(), 0.7) |
| 71 | + }); |
| 72 | + } catch (error) { |
| 73 | + console.error(`[EnrichLayer Mock] Error: ${(error as Error).message}`); |
| 74 | + return res.status(500).json({ |
| 75 | + code: '500', |
| 76 | + error: 'Internal Server Error' |
| 77 | + }); |
| 78 | + } |
| 79 | +}); |
| 80 | + |
| 81 | +export default router; |
0 commit comments