powr-sdk-api 2.4.0 → 2.4.2

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.
@@ -143,7 +143,8 @@ router.get('/getCount/:formName', async (req, res) => {
143
143
  const {
144
144
  projectId
145
145
  } = req.query;
146
- const studentsFormCollection = getDb().collection('studentsForm');
146
+ const db = await getDb();
147
+ const studentsFormCollection = db.collection('studentsForm');
147
148
 
148
149
  // Build query object
149
150
  let query = {
@@ -205,7 +206,8 @@ router.post('/create-form', upload.single('jsonFile'), async (req, res) => {
205
206
  message: 'formName is required in JSON data'
206
207
  });
207
208
  }
208
- const powrFormCollection = getDb().collection('powrForm');
209
+ const db = await getDb();
210
+ const powrFormCollection = db.collection('powrForm');
209
211
  const existingForm = await powrFormCollection.findOne({
210
212
  formName: formData.formName,
211
213
  projectId: projectId
@@ -9,10 +9,10 @@ const {
9
9
  // Get all users for a project
10
10
  router.get("/", async (req, res) => {
11
11
  try {
12
- const {
13
- projectId
14
- } = req.query;
15
- const profiles = await getDb().collection("profiles").find({
12
+ const projectId = req.projectId; // Use middleware-injected projectId
13
+
14
+ const db = await getDb();
15
+ const profiles = await db.collection("profiles").find({
16
16
  projectId: projectId
17
17
  }).toArray();
18
18
  if (profiles.length === 0) {
@@ -24,7 +24,7 @@ router.get("/", async (req, res) => {
24
24
 
25
25
  // Get core user data for all profiles
26
26
  const userIds = profiles.map(profile => profile.userId);
27
- const users = await getDb().collection("users").find({
27
+ const users = await db.collection("users").find({
28
28
  _id: {
29
29
  $in: userIds
30
30
  }
@@ -6,15 +6,12 @@
6
6
  const {
7
7
  MongoClient
8
8
  } = require('mongodb');
9
- const {
10
- getConfig
11
- } = require('../config');
9
+ const config = require('../config');
12
10
  let client = null;
13
11
  let db = null;
14
12
  const connectDB = async () => {
15
- const config = getConfig();
16
13
  if (!config.mongoUri) {
17
- throw new Error('MONGODB_URI environment variable is required');
14
+ throw new Error('POWR_DB_URI environment variable is required');
18
15
  }
19
16
  try {
20
17
  client = new MongoClient(config.mongoUri);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powr-sdk-api",
3
- "version": "2.4.0",
3
+ "version": "2.4.2",
4
4
  "description": "Shared API core library for PowrStack projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",