Niansuh commited on
Commit
e31fd5b
1 Parent(s): cb15153

Update routes/admin.js

Browse files
Files changed (1) hide show
  1. routes/admin.js +15 -4
routes/admin.js CHANGED
@@ -1,18 +1,29 @@
1
  const express = require('express');
2
  const router = express.Router();
 
3
 
4
  router.get('/', (req, res) => {
 
5
  if (req.session.user && req.session.user.role === 'admin') {
6
- res.render('admin.html');
7
  } else {
8
  res.status(403).send('Unauthorized');
9
  }
10
  });
11
 
12
- // Route to add endpoint, key, and model
13
  router.post('/add-endpoint', (req, res) => {
14
- // Logic to add endpoint to database
15
- res.send('Endpoint added');
 
 
 
 
 
 
 
 
 
16
  });
17
 
18
  module.exports = router;
 
1
  const express = require('express');
2
  const router = express.Router();
3
+ const db = require('../database');
4
 
5
  router.get('/', (req, res) => {
6
+ // Only admins can access
7
  if (req.session.user && req.session.user.role === 'admin') {
8
+ res.render('admin');
9
  } else {
10
  res.status(403).send('Unauthorized');
11
  }
12
  });
13
 
14
+ // Add endpoint
15
  router.post('/add-endpoint', (req, res) => {
16
+ // Logic for admin to add an endpoint
17
+ res.redirect('/admin');
18
+ });
19
+
20
+ // Manage credits
21
+ router.post('/update-credits', (req, res) => {
22
+ const { userId, credits } = req.body;
23
+ db.query(`UPDATE users SET credits = ? WHERE id = ?`, [credits, userId], (err) => {
24
+ if (err) return res.status(500).send('Error updating credits');
25
+ res.redirect('/admin');
26
+ });
27
  });
28
 
29
  module.exports = router;