-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
349 lines (319 loc) · 11.3 KB
/
Copy pathserver.js
File metadata and controls
349 lines (319 loc) · 11.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
// ─────────────────────────────────────────────
// TherapistMatch — Backend Server (Node.js / Express)
// Run: npm install && node server.js
// ─────────────────────────────────────────────
const express = require('express');
const cors = require('cors');
const path = require('path');
const app = express();
const PORT = process.env.PORT || 3000;
// ─── MIDDLEWARE ───
app.use(cors());
app.use(express.json());
app.use(express.static(__dirname));
// ─────────────────────────────────────────────
// In-Memory "Database" (replace with real DB)
// ─────────────────────────────────────────────
let bookings = [];
const therapists = [
{
id: 1,
name: 'Dr. Meera Rajan',
title: 'Clinical Psychologist',
experience: 9,
specializations: ['Anxiety', 'CBT', 'Mindfulness'],
rating: 4.9,
reviews: 128,
price: 900,
currency: 'INR',
modes: ['video', 'phone'],
languages: ['English', 'Hindi', 'Tamil'],
availability: true,
avatar: 'https://i.pravatar.cc/100?img=47',
verified: true,
bio: 'Dr. Meera brings a warm, CBT-integrated approach to anxiety and stress management. She focuses on practical tools and long-term wellbeing.',
},
{
id: 2,
name: 'Dr. Aryan Bose',
title: 'Trauma Specialist',
experience: 12,
specializations: ['Trauma', 'DBT', 'Depression'],
rating: 4.8,
reviews: 96,
price: 700,
currency: 'INR',
modes: ['inperson', 'video'],
languages: ['English', 'Bengali', 'Hindi'],
availability: true,
avatar: 'https://i.pravatar.cc/100?img=12',
verified: true,
bio: 'Dr. Aryan specializes in PTSD and complex trauma using DBT and somatic approaches, with 12 years of clinical experience.',
},
{
id: 3,
name: 'Dr. Sana Qureshi',
title: 'Couples Therapist',
experience: 7,
specializations: ['Couples', 'Anxiety', 'Communication'],
rating: 4.9,
reviews: 74,
price: 1200,
currency: 'INR',
modes: ['video', 'phone'],
languages: ['English', 'Urdu', 'Hindi'],
availability: true,
avatar: 'https://i.pravatar.cc/100?img=32',
verified: true,
bio: 'Dr. Sana brings the Gottman Method and EFT to couples work, helping partners rebuild trust and communication.',
},
{
id: 4,
name: 'Dr. Vikram Nair',
title: 'Psychiatrist',
experience: 15,
specializations: ['Depression', 'CBT', 'OCD'],
rating: 4.7,
reviews: 211,
price: 1500,
currency: 'INR',
modes: ['inperson', 'video'],
languages: ['English', 'Malayalam', 'Hindi'],
availability: true,
avatar: 'https://i.pravatar.cc/100?img=68',
verified: true,
bio: 'One of India\'s leading psychiatrists, Dr. Vikram combines pharmacotherapy with CBT for depression and OCD.',
},
{
id: 5,
name: 'Dr. Priya Sharma',
title: 'EMDR Therapist',
experience: 10,
specializations: ['Anxiety', 'PTSD', 'EMDR'],
rating: 5.0,
reviews: 62,
price: 800,
currency: 'INR',
modes: ['video'],
languages: ['English', 'Hindi'],
availability: true,
avatar: 'https://i.pravatar.cc/100?img=25',
verified: true,
bio: 'Certified EMDR therapist specializing in trauma resolution, anxiety disorders, and phobias through evidence-based desensitization therapy.',
},
{
id: 6,
name: 'Dr. Rahul Das',
title: 'Family Therapist',
experience: 8,
specializations: ['Family', 'Depression', 'Couples'],
rating: 4.8,
reviews: 88,
price: 600,
currency: 'INR',
modes: ['inperson', 'phone'],
languages: ['English', 'Bengali', 'Hindi', 'Odia'],
availability: true,
avatar: 'https://i.pravatar.cc/100?img=59',
verified: true,
bio: 'Dr. Rahul focuses on systemic family therapy, helping families navigate conflict, grief, and relationship repair.',
},
{
id: 7,
name: 'Dr. Maya Iyer',
title: 'Clinical Psychologist',
experience: 5,
specializations: ['Anxiety', 'Depression'],
rating: 4.6,
reviews: 45,
price: 600,
currency: 'INR',
modes: ['video'],
languages: ['English'],
availability: true,
avatar: 'https://i.pravatar.cc/100?img=10',
verified: true,
bio: 'Focuses on modern anxiety and depression treatments.'
},
{
id: 8,
name: 'Dr. Rohan Mehta',
title: 'Trauma Specialist',
experience: 14,
specializations: ['Trauma', 'CBT'],
rating: 4.8,
reviews: 112,
price: 1000,
currency: 'INR',
modes: ['inperson'],
languages: ['English', 'Hindi'],
availability: true,
avatar: 'https://i.pravatar.cc/100?img=11',
verified: true,
bio: 'Extensive trauma specialization via in-person consultations.'
},
{
id: 9,
name: 'Dr. Anjali Verma',
title: 'Marriage Counselor',
experience: 9,
specializations: ['Couples', 'Anxiety'],
rating: 4.9,
reviews: 89,
price: 950,
currency: 'INR',
modes: ['video', 'inperson'],
languages: ['English'],
availability: true,
avatar: 'https://i.pravatar.cc/100?img=20',
verified: true,
bio: 'Deep insight into modern couples therapy.'
}
];
// ─────────────────────────────────────────────
// ROUTES
// ─────────────────────────────────────────────
// Health check
app.get('/api/health', (req, res) => {
res.json({ status: 'ok', timestamp: new Date().toISOString(), service: 'TherapistMatch API' });
});
// ─── GET all therapists ───
app.get('/api/therapists', (req, res) => {
const { specialization, minPrice, maxPrice, mode, language, sort } = req.query;
let results = [...therapists];
if (specialization) {
results = results.filter(t =>
t.specializations.some(s => s.toLowerCase().includes(specialization.toLowerCase()))
);
}
if (minPrice) results = results.filter(t => t.price >= parseInt(minPrice));
if (maxPrice) results = results.filter(t => t.price <= parseInt(maxPrice));
if (mode) results = results.filter(t => t.modes.includes(mode.toLowerCase()));
if (language) {
results = results.filter(t =>
t.languages.some(l => l.toLowerCase().includes(language.toLowerCase()))
);
}
if (sort === 'price_asc') results.sort((a, b) => a.price - b.price);
else if (sort === 'price_desc') results.sort((a, b) => b.price - a.price);
else if (sort === 'rating') results.sort((a, b) => b.rating - a.rating);
res.json({ success: true, count: results.length, data: results });
});
// ─── GET single therapist ───
app.get('/api/therapists/:id', (req, res) => {
const therapist = therapists.find(t => t.id === parseInt(req.params.id));
if (!therapist) return res.status(404).json({ success: false, message: 'Therapist not found' });
res.json({ success: true, data: therapist });
});
// ─── GET therapist availability ───
app.get('/api/therapists/:id/availability', (req, res) => {
const therapist = therapists.find(t => t.id === parseInt(req.params.id));
if (!therapist) return res.status(404).json({ success: false, message: 'Not found' });
// Generate mock availability for next 30 days
const slots = [];
const today = new Date();
for (let i = 1; i <= 30; i++) {
const date = new Date(today);
date.setDate(today.getDate() + i);
if (date.getDay() !== 0) { // Not Sunday
const times = [];
if (Math.random() > 0.3) times.push('10:00 AM');
if (Math.random() > 0.3) times.push('11:30 AM');
if (Math.random() > 0.4) times.push('2:00 PM');
if (Math.random() > 0.4) times.push('4:00 PM');
if (Math.random() > 0.5) times.push('6:30 PM');
if (times.length) slots.push({ date: date.toISOString().split('T')[0], times });
}
}
res.json({ success: true, therapistId: req.params.id, slots });
});
// ─── POST create booking ───
app.post('/api/bookings', (req, res) => {
const { therapist, slot, day, month, sessionType, name, email, notes } = req.body;
if (!therapist || !slot) {
return res.status(400).json({ success: false, message: 'therapist and slot are required' });
}
const booking = {
id: `BK${Date.now()}`,
therapist,
slot,
day: day || null,
month: month || null,
sessionType: sessionType || 'video',
userName: name || 'Anonymous',
userEmail: email || '',
notes: notes || '',
status: 'confirmed',
createdAt: new Date().toISOString()
};
bookings.push(booking);
console.log(`[BOOKING] ${booking.id} — ${therapist} on ${month} ${day} at ${slot}`);
res.status(201).json({
success: true,
message: 'Booking confirmed!',
data: booking
});
});
// ─── GET all bookings ───
app.get('/api/bookings', (req, res) => {
res.json({ success: true, count: bookings.length, data: bookings });
});
// ─── GET single booking ───
app.get('/api/bookings/:id', (req, res) => {
const booking = bookings.find(b => b.id === req.params.id);
if (!booking) return res.status(404).json({ success: false, message: 'Booking not found' });
res.json({ success: true, data: booking });
});
// ─── DELETE booking ───
app.delete('/api/bookings/:id', (req, res) => {
const idx = bookings.findIndex(b => b.id === req.params.id);
if (idx === -1) return res.status(404).json({ success: false, message: 'Booking not found' });
bookings.splice(idx, 1);
res.json({ success: true, message: 'Booking cancelled' });
});
// ─── POST onboarding quiz → match ───
app.post('/api/quiz/match', (req, res) => {
const { concern, budget, mode, language } = req.body;
let matches = [...therapists];
if (concern) {
matches = matches.filter(t =>
t.specializations.some(s => s.toLowerCase().includes(concern.toLowerCase()))
);
}
if (budget) {
matches = matches.filter(t => t.price <= parseInt(budget));
}
if (mode) {
matches = matches.filter(t => t.modes.includes(mode));
}
if (language) {
matches = matches.filter(t =>
t.languages.some(l => l.toLowerCase().includes(language.toLowerCase()))
);
}
// Sort by rating
matches.sort((a, b) => b.rating - a.rating);
res.json({
success: true,
matchCount: matches.length,
message: matches.length ? `${matches.length} therapists matched!` : 'No exact match — showing all therapists.',
data: matches.length ? matches.slice(0, 3) : therapists.slice(0, 3)
});
});
// ─── Catch-all → serve frontend ───
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, 'index.html'));
});
// ─── START ───
app.listen(PORT, () => {
console.log(`\n🧠 TherapistMatch API running at http://localhost:${PORT}`);
console.log(`📋 Endpoints:`);
console.log(` GET /api/health`);
console.log(` GET /api/therapists`);
console.log(` GET /api/therapists/:id`);
console.log(` GET /api/therapists/:id/availability`);
console.log(` POST /api/bookings`);
console.log(` GET /api/bookings`);
console.log(` DELETE /api/bookings/:id`);
console.log(` POST /api/quiz/match\n`);
});