Reaperxxxx commited on
Commit
638d329
·
verified ·
1 Parent(s): eedf20a

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +33 -0
index.js CHANGED
@@ -236,6 +236,39 @@ app.get('/user/:id/info', async (req, res) => {
236
  }
237
  });
238
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
239
  // GET /group/:id/meta → returns group metadata from MongoDB (names.json)
240
  app.get('/group/:id/meta', async (req, res) => {
241
  const groupId = req.params.id;
 
236
  }
237
  });
238
 
239
+ app.get('/user/:id/theme', async (req, res) => {
240
+ const userId = req.params.id;
241
+ const filename = 'data/themes.json';
242
+
243
+ const client = new MongoClient(MONGO_URI);
244
+ try {
245
+ await client.connect();
246
+ const db = client.db(DB_NAME);
247
+ const collection = db.collection(COLLECTION_NAME);
248
+
249
+ // Find the document for themes.json
250
+ const doc = await collection.findOne({ filename });
251
+
252
+ if (!doc || !doc.data || !doc.data[userId]) {
253
+ return res.status(404).json({ status: false, message: 'User theme not found' });
254
+ }
255
+
256
+ const { theme, lastUpdated } = doc.data[userId];
257
+
258
+ return res.json({
259
+ status: true,
260
+ userId,
261
+ theme,
262
+ lastUpdated
263
+ });
264
+
265
+ } catch (err) {
266
+ return res.status(500).json({ status: false, error: err.message });
267
+ } finally {
268
+ await client.close();
269
+ }
270
+ });
271
+
272
  // GET /group/:id/meta → returns group metadata from MongoDB (names.json)
273
  app.get('/group/:id/meta', async (req, res) => {
274
  const groupId = req.params.id;