powr-sdk-api 2.4.5 → 2.4.6

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.
@@ -55,7 +55,8 @@ router.post("/register", async (req, res) => {
55
55
  }]
56
56
  };
57
57
  console.log(q);
58
- const existingUser = await getDb().collection("users").findOne(q);
58
+ const db = await getDb();
59
+ const existingUser = await db.collection("users").findOne(q);
59
60
  if (existingUser) {
60
61
  return res.status(400).json({
61
62
  success: false,
@@ -72,7 +73,7 @@ router.post("/register", async (req, res) => {
72
73
  password: hashedPassword,
73
74
  createdAt: new Date()
74
75
  };
75
- const result = await getDb().collection("users").insertOne(newUser);
76
+ const result = await db.collection("users").insertOne(newUser);
76
77
  if (projectId) {
77
78
  const newProfile = {
78
79
  userId: result.insertedId,
@@ -80,7 +81,7 @@ router.post("/register", async (req, res) => {
80
81
  createdAt: new Date(),
81
82
  updatedAt: new Date()
82
83
  };
83
- await getDb().collection("profiles").insertOne(newProfile);
84
+ await db.collection("profiles").insertOne(newProfile);
84
85
  }
85
86
  return res.status(201).json({
86
87
  success: true,
@@ -22,7 +22,8 @@ router.get('/', async (req, res) => {
22
22
  message: 'projectId is required.'
23
23
  });
24
24
  }
25
- const invoiceData = await getDb().collection("invoices").find(query).toArray();
25
+ const db = await getDb();
26
+ const invoiceData = await db.collection("invoices").find(query).toArray();
26
27
  return res.status(200).json({
27
28
  success: true,
28
29
  invoices: invoiceData
@@ -50,7 +51,8 @@ router.get('/:invoiceId', async (req, res) => {
50
51
  });
51
52
  }
52
53
  const _id = new ObjectId(invoiceId);
53
- const invoiceData = await getDb().collection("invoices").findOne({
54
+ const db = await getDb();
55
+ const invoiceData = await db.collection("invoices").findOne({
54
56
  _id,
55
57
  projectId
56
58
  });
@@ -95,7 +97,8 @@ router.post('/', async (req, res) => {
95
97
  };
96
98
  invoice.projectId = projectId;
97
99
  try {
98
- const result = await getDb().collection("invoices").insertOne(invoice);
100
+ const db = await getDb();
101
+ const result = await db.collection("invoices").insertOne(invoice);
99
102
  if (result && result.insertedId) {
100
103
  return res.status(201).json({
101
104
  success: true,
@@ -144,7 +147,8 @@ router.put('/:invoiceId', async (req, res) => {
144
147
  }
145
148
  const updateData = req.body;
146
149
  try {
147
- const result = await getDb().collection("invoices").updateOne(filter, {
150
+ const db = await getDb();
151
+ const result = await db.collection("invoices").updateOne(filter, {
148
152
  $set: updateData
149
153
  });
150
154
  return res.status(200).json({
@@ -37,7 +37,8 @@ router.post('/', async (req, res) => {
37
37
  query.contentId = contentId;
38
38
  setObj.contentId = contentId;
39
39
  }
40
- const response = await getDb().collection('likes').updateOne(query, {
40
+ const db = await getDb();
41
+ const response = await db.collection('likes').updateOne(query, {
41
42
  $set: setObj
42
43
  }, {
43
44
  upsert: true
@@ -73,7 +74,8 @@ router.get('/', async (req, res) => {
73
74
  if (contentId) {
74
75
  query.contentId = contentId;
75
76
  }
76
- const likes = await getDb().collection('likes').find(query).toArray();
77
+ const db = await getDb();
78
+ const likes = await db.collection('likes').find(query).toArray();
77
79
  const likesCount = likes.filter(like => like.liked === true).length;
78
80
  const unlikesCount = likes.filter(like => like.liked === false).length;
79
81
  return res.status(200).json({
@@ -104,7 +106,8 @@ router.get('/:likeId', async (req, res) => {
104
106
  };
105
107
  if (projectId) filter.projectId = projectId;
106
108
  if (contentId) filter.contentId = contentId;
107
- const like = await getDb().collection('likes').findOne(filter);
109
+ const db = await getDb();
110
+ const like = await db.collection('likes').findOne(filter);
108
111
  if (!like) {
109
112
  return res.status(404).json({
110
113
  success: false,
@@ -17,7 +17,8 @@ router.get('/', async (req, res) => {
17
17
  projectId
18
18
  };
19
19
  console.log("Filter.....:", query);
20
- const notificationData = await getDb().collection('notifications').find(query).toArray();
20
+ const db = await getDb();
21
+ const notificationData = await db.collection('notifications').find(query).toArray();
21
22
  if (!notificationData || notificationData.length === 0) {
22
23
  console.log("Data not found.");
23
24
  return res.status(200).json({
@@ -64,7 +65,8 @@ router.post('/', async (req, res) => {
64
65
  createdAt: new Date()
65
66
  };
66
67
  try {
67
- const result = await getDb().collection('notifications').insertOne(notificationData);
68
+ const db = await getDb();
69
+ const result = await db.collection('notifications').insertOne(notificationData);
68
70
  if (result && result.insertedId) {
69
71
  console.log("Notification added with ID:", result.insertedId);
70
72
 
@@ -21,7 +21,8 @@ router.get('/', async (req, res) => {
21
21
  message: 'projectId is required.'
22
22
  });
23
23
  }
24
- const routesData = await getDb().collection("routes").find(query).toArray();
24
+ const db = await getDb();
25
+ const routesData = await db.collection("routes").find(query).toArray();
25
26
  return res.status(200).json({
26
27
  success: true,
27
28
  allroutes: routesData
@@ -55,7 +56,8 @@ router.post('/', async (req, res) => {
55
56
  message: 'Request body is empty or invalid.'
56
57
  });
57
58
  }
58
- const result = await getDb().collection('routes').insertOne(newRoute);
59
+ const db = await getDb();
60
+ const result = await db.collection('routes').insertOne(newRoute);
59
61
  return res.status(201).json({
60
62
  success: true,
61
63
  entry: result.ops ? result.ops[0] : newRoute
@@ -97,14 +99,15 @@ router.put('/:route', async (req, res) => {
97
99
  route,
98
100
  projectId
99
101
  };
100
- const existingRoute = await getDb().collection('routes').findOne(query);
102
+ const db = await getDb();
103
+ const existingRoute = await db.collection('routes').findOne(query);
101
104
  if (!existingRoute) {
102
105
  return res.status(404).json({
103
106
  success: false,
104
107
  message: 'Route not found.'
105
108
  });
106
109
  }
107
- const result = await getDb().collection('routes').updateOne(query, {
110
+ const result = await db.collection('routes').updateOne(query, {
108
111
  $set: {
109
112
  code
110
113
  }
@@ -115,7 +118,7 @@ router.put('/:route', async (req, res) => {
115
118
  message: 'Route not found.'
116
119
  });
117
120
  }
118
- const updatedRoute = await getDb().collection('routes').findOne(query);
121
+ const updatedRoute = await db.collection('routes').findOne(query);
119
122
  return res.status(200).json({
120
123
  success: true,
121
124
  entry: updatedRoute
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "powr-sdk-api",
3
- "version": "2.4.5",
3
+ "version": "2.4.6",
4
4
  "description": "Shared API core library for PowrStack projects",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",