forked from ahmadbasyouni10/ctp-hackathon-24
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfeedback.js
42 lines (33 loc) · 1 KB
/
feedback.js
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
import express from 'express';
import { MongoClient } from 'mongodb';
import dotenv from 'dotenv';
dotenv.config();
const router = express.Router();
const uri = process.env.MONGO_URI;
router.post('/submit-feedback', async (req, res) => {
const { question, details, school } = req.body;
const client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
ssl: true,
tlsAllowInvalidCertificates: true,
});
try {
await client.connect();
const database = client.db("cuny_guide");
const collection = database.collection("feedback");
const result = await collection.insertOne({
question,
details,
school,
timestamp: new Date(),
});
res.status(200).json({ message: "Feedback submitted successfully" });
} catch (error) {
console.error("Error submitting feedback:", error);
res.status(500).json({ error: "An error occurred while submitting feedback" });
} finally {
await client.close();
}
});
export default router;