powr-sdk-api 2.0.8 → 2.1.0

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/README.md CHANGED
@@ -18,7 +18,7 @@ const { createAdminRoutes } = require('powr-sdk-api');
18
18
 
19
19
  const app = express();
20
20
 
21
- // Mount admin routes (uses environment variables)
21
+ // Mount admin routes (projectId from environment)
22
22
  app.use('/admin', createAdminRoutes());
23
23
 
24
24
  app.listen(3000);
@@ -23,7 +23,7 @@ const upload = multer({
23
23
 
24
24
  // GET all powrForm data based on projectId
25
25
  router.get("/powrform", async (req, res) => {
26
- const projectId = req.query.projectId;
26
+ const projectId = req.projectId;
27
27
  try {
28
28
  const db = await getDb();
29
29
  const collection = db.collection("powrForm");
@@ -51,13 +51,11 @@ router.get('/:formName', async (req, res) => {
51
51
  const {
52
52
  formName
53
53
  } = req.params;
54
- const {
55
- projectId
56
- } = req.query;
54
+ const projectId = req.projectId;
57
55
  if (!projectId) {
58
56
  return res.status(400).json({
59
57
  success: false,
60
- message: 'projectId is required as query parameter'
58
+ message: 'projectId is required'
61
59
  });
62
60
  }
63
61
  const db = await getDb();
@@ -90,9 +88,7 @@ router.get('/:formName', async (req, res) => {
90
88
  router.post('/studentform', async (req, res) => {
91
89
  try {
92
90
  const formData = req.body;
93
- const {
94
- projectId
95
- } = req.query;
91
+ const projectId = req.projectId;
96
92
  const {
97
93
  whatsapp,
98
94
  formName,
@@ -19,9 +19,18 @@ const slidesRoutes = require('./slides');
19
19
  const notificationsRoutes = require('./notifications');
20
20
  const createAdminRoutes = () => {
21
21
  // Get config from environment variables
22
-
22
+ const {
23
+ getConfig
24
+ } = require('../config');
25
+ const config = getConfig();
23
26
  const router = express.Router();
24
27
 
28
+ // Middleware to inject projectId into all requests
29
+ router.use((req, res, next) => {
30
+ req.projectId = config.projectId;
31
+ next();
32
+ });
33
+
25
34
  // Mount all route modules
26
35
  router.use('/comments', commentsRoutes);
27
36
  // router.use('/files', filesRoutes); // Commented out for now
@@ -12,12 +12,12 @@ const {
12
12
  //add ratings
13
13
  router.post("/", async (req, res) => {
14
14
  const {
15
- projectId,
16
15
  itemId,
17
16
  rating,
18
17
  review,
19
18
  userId
20
19
  } = req.body;
20
+ const projectId = req.projectId;
21
21
  if (!rating || !review) {
22
22
  return res.status(400).json({
23
23
  success: false,
@@ -61,14 +61,14 @@ router.post("/", async (req, res) => {
61
61
  //get ratings
62
62
  router.get("/", async (req, res) => {
63
63
  const {
64
- projectId,
65
64
  itemId,
66
65
  userId
67
66
  } = req.query;
67
+ const projectId = req.projectId;
68
68
  if (!projectId) {
69
69
  return res.status(400).json({
70
70
  success: false,
71
- message: "projectId is required in query params."
71
+ message: "projectId is required."
72
72
  });
73
73
  }
74
74
  try {
@@ -103,9 +103,9 @@ router.get("/", async (req, res) => {
103
103
  // delete ratings
104
104
  router.delete("/", async (req, res) => {
105
105
  const {
106
- ratingId,
107
- projectId
106
+ ratingId
108
107
  } = req.query;
108
+ const projectId = req.projectId;
109
109
  if (!ratingId || !projectId) {
110
110
  return res.status(400).json({
111
111
  success: false,
@@ -140,9 +140,9 @@ router.delete("/", async (req, res) => {
140
140
  // Calculate average rating
141
141
  router.get("/average", async (req, res) => {
142
142
  const {
143
- projectId,
144
143
  itemId
145
144
  } = req.query;
145
+ const projectId = req.projectId;
146
146
  if (!projectId || !itemId) {
147
147
  return res.status(400).json({
148
148
  success: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powr-sdk-api",
3
- "version": "2.0.8",
3
+ "version": "2.1.0",
4
4
  "description": "Shared API core library for PowrStack projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",