powr-sdk-api 2.0.5 → 2.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/forms.js +3 -3
- package/dist/admin/ratings.js +8 -4
- package/dist/services/mongo.js +3 -2
- package/package.json +1 -1
package/dist/admin/forms.js
CHANGED
|
@@ -25,7 +25,7 @@ const upload = multer({
|
|
|
25
25
|
router.get("/powrform", async (req, res) => {
|
|
26
26
|
const projectId = req.query.projectId;
|
|
27
27
|
try {
|
|
28
|
-
const db = getDb();
|
|
28
|
+
const db = await getDb();
|
|
29
29
|
const collection = db.collection("powrForm");
|
|
30
30
|
const forms = await collection.find({
|
|
31
31
|
projectId
|
|
@@ -60,7 +60,7 @@ router.get('/:formName', async (req, res) => {
|
|
|
60
60
|
message: 'projectId is required as query parameter'
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
|
-
const db = getDb();
|
|
63
|
+
const db = await getDb();
|
|
64
64
|
const collection = db.collection("powrForm");
|
|
65
65
|
const formData = await collection.findOne({
|
|
66
66
|
formName,
|
|
@@ -99,7 +99,7 @@ router.post('/studentform', async (req, res) => {
|
|
|
99
99
|
email,
|
|
100
100
|
...otherFormFields
|
|
101
101
|
} = formData;
|
|
102
|
-
const db = getDb();
|
|
102
|
+
const db = await getDb();
|
|
103
103
|
const studentsFormCollection = db.collection('studentsForm');
|
|
104
104
|
const existingForm = await studentsFormCollection.findOne({
|
|
105
105
|
whatsapp: whatsapp,
|
package/dist/admin/ratings.js
CHANGED
|
@@ -33,7 +33,8 @@ router.post("/", async (req, res) => {
|
|
|
33
33
|
createdAt: new Date()
|
|
34
34
|
};
|
|
35
35
|
try {
|
|
36
|
-
const
|
|
36
|
+
const db = await getDb();
|
|
37
|
+
const result = await db.collection("ratings").insertOne(ratingData);
|
|
37
38
|
if (result && result.insertedId) {
|
|
38
39
|
console.log("ratings added with ID:", result.insertedId);
|
|
39
40
|
return res.status(200).json({
|
|
@@ -77,7 +78,8 @@ router.get("/", async (req, res) => {
|
|
|
77
78
|
if (itemId) query.itemId = itemId;
|
|
78
79
|
if (userId) query.userId = userId;
|
|
79
80
|
console.log("Filter....:", query);
|
|
80
|
-
const
|
|
81
|
+
const db = await getDb();
|
|
82
|
+
const ratingData = await db.collection("ratings").find(query).toArray();
|
|
81
83
|
if (!ratingData || ratingData.length === 0) {
|
|
82
84
|
console.log("Data not found.");
|
|
83
85
|
return res.status(200).json({
|
|
@@ -111,7 +113,8 @@ router.delete("/", async (req, res) => {
|
|
|
111
113
|
});
|
|
112
114
|
}
|
|
113
115
|
try {
|
|
114
|
-
const
|
|
116
|
+
const db = await getDb();
|
|
117
|
+
const result = await db.collection("ratings").deleteOne({
|
|
115
118
|
_id: new ObjectId(ratingId),
|
|
116
119
|
projectId: projectId
|
|
117
120
|
});
|
|
@@ -147,7 +150,8 @@ router.get("/average", async (req, res) => {
|
|
|
147
150
|
});
|
|
148
151
|
}
|
|
149
152
|
try {
|
|
150
|
-
const
|
|
153
|
+
const db = await getDb();
|
|
154
|
+
const result = await db.collection("ratings").aggregate([{
|
|
151
155
|
$match: {
|
|
152
156
|
projectId,
|
|
153
157
|
itemId
|
package/dist/services/mongo.js
CHANGED
|
@@ -7,13 +7,14 @@ const {
|
|
|
7
7
|
MongoClient
|
|
8
8
|
} = require('mongodb');
|
|
9
9
|
const {
|
|
10
|
-
|
|
10
|
+
getConfig
|
|
11
11
|
} = require('../config');
|
|
12
12
|
let client = null;
|
|
13
13
|
let db = null;
|
|
14
14
|
const connectDB = async () => {
|
|
15
|
+
const config = getConfig();
|
|
15
16
|
if (!config.mongoUri) {
|
|
16
|
-
throw new Error('
|
|
17
|
+
throw new Error('MONGODB_URI environment variable is required');
|
|
17
18
|
}
|
|
18
19
|
try {
|
|
19
20
|
client = new MongoClient(config.mongoUri);
|