Skip to content

Commit

Permalink
feat: ITP-126
Browse files Browse the repository at this point in the history
  • Loading branch information
RickyRAV committed Nov 4, 2023
1 parent 56d40f3 commit 4b31535
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions controllers/historyController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import {prisma} from "../config/prismaClient.js";

export const userHistory = async (req, res) => {
const { user: { id: user_id } } = req.user;

try {
const quizzes = await prisma.quizzes.findMany({
where: { user_id },
select: {
id: true,
quiz_title: true,
total_time_taken: true
}
});
res.json(quizzes);
} catch (error) {
res.status(500).json({ error: error.message });
}
};
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { configureSwagger } from './config/swagger.js';
import { startServer } from './config/startServer.js';
import authRoutes from './routes/authRoutes.js';
import quizRoutes from "./routes/quizRoutes.js";
import historyRoutes from "./routes/historyRoutes.js";

const app = express();

configureMiddlewares(app);
configureSwagger(app);
authRoutes(app);
quizRoutes(app);
historyRoutes(app);

startServer(app).catch(e => console.error(e));
8 changes: 8 additions & 0 deletions routes/historyRoutes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import {isAuthenticated} from "../middlewares/isAuthenticated.js";
import {
userHistory
} from '../controllers/historyController.js';

export default (app) => {
app.get('/quizzes', isAuthenticated, userHistory);
};

0 comments on commit 4b31535

Please sign in to comment.