re-organized / added instructor router
This commit is contained in:
parent
85087687d7
commit
039492ea34
4 changed files with 34 additions and 27 deletions
|
|
@ -3,6 +3,7 @@ const { PrismaClient } = require('@prisma/client');
|
||||||
const app = express();
|
const app = express();
|
||||||
|
|
||||||
const adminRouter = require("./routes/AdminRouter");
|
const adminRouter = require("./routes/AdminRouter");
|
||||||
|
const instructorRouter = require("./routes/InstructorRouter");
|
||||||
const studentRouter = require("./routes/StudentRouter");
|
const studentRouter = require("./routes/StudentRouter");
|
||||||
|
|
||||||
// require('dotenv').config(); // prisma client already loads .env apparently, double check before deploying
|
// require('dotenv').config(); // prisma client already loads .env apparently, double check before deploying
|
||||||
|
|
@ -16,31 +17,7 @@ app.use(express.json());
|
||||||
//use routes of other pages
|
//use routes of other pages
|
||||||
app.use("/student", studentRouter);
|
app.use("/student", studentRouter);
|
||||||
app.use("/admin", adminRouter);
|
app.use("/admin", adminRouter);
|
||||||
|
app.use("/instructor", instructorRouter);
|
||||||
// Fetch top users (update logic as per your requirements)
|
|
||||||
app.get('/update', async (req, res) => {
|
|
||||||
try {
|
|
||||||
const users = await prisma.user.findMany({
|
|
||||||
orderBy: { username: 'asc' }, // Example sorting
|
|
||||||
});
|
|
||||||
res.json(users);
|
|
||||||
} catch (err) {
|
|
||||||
res.status(500).json({ error: err.message });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// For new users sign-up via Google oAuth:
|
|
||||||
app.post('/register-user', async (req, res) => {
|
|
||||||
try {
|
|
||||||
const { username, password } = req.body;
|
|
||||||
const newUser = await prisma.user.create({
|
|
||||||
data: { username, email, password },
|
|
||||||
});
|
|
||||||
res.json({ message: 'User added successfully', user: newUser });
|
|
||||||
} catch (err) {
|
|
||||||
res.status(500).json({ error: err.message });
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.listen(port, () => {
|
||||||
console.log(`Server running at http://localhost:${port}`);
|
console.log(`Server running at http://localhost:${port}`);
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
|
||||||
#
|
#
|
||||||
|
|
||||||
app = 'snakebyte'
|
app = 'db-user-service'
|
||||||
primary_region = 'sea'
|
primary_region = 'sea'
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
|
|
|
||||||
|
|
@ -9,4 +9,17 @@ adminRouter.get('/query', async (req, res) => {
|
||||||
res.status(400).json({ error: 'Custom queries are not supported.' });
|
res.status(400).json({ error: 'Custom queries are not supported.' });
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = adminRouter;
|
// Fetch top users (update logic as per your requirements)
|
||||||
|
adminRouter.get('/update', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const users = await prisma.user.findMany({
|
||||||
|
orderBy: { username: 'asc' }, // Example sorting
|
||||||
|
});
|
||||||
|
res.json(users);
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = adminRouter;
|
||||||
|
|
|
||||||
17
user-db-service/routes/InstructorRouter.js
Normal file
17
user-db-service/routes/InstructorRouter.js
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
const express = require("express");
|
||||||
|
const instructorRouter = express.Router();
|
||||||
|
|
||||||
|
// For new users sign-up via Google oAuth:
|
||||||
|
instructorRouter.post('/register-user', async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { username, password } = req.body;
|
||||||
|
const newUser = await prisma.user.create({
|
||||||
|
data: { username, email, password },
|
||||||
|
});
|
||||||
|
res.json({ message: 'User added successfully', user: newUser });
|
||||||
|
} catch (err) {
|
||||||
|
res.status(500).json({ error: err.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
module.exports = instructorRouter;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue