Skip to content

Commit

Permalink
Merge pull request #24 from Code-the-Dream-School/home_page_api
Browse files Browse the repository at this point in the history
dashboard status
  • Loading branch information
iamrahimi authored Jan 19, 2025
2 parents d344fd7 + 188c2aa commit 6c82c52
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/controllers/projectController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ const projectModel = require("../models/projectModel");
const {getLoggedInUserId, checkProjectOwner, checkUserRoleAdmin} = require('../services/userService');

const projectController = {

dashboard: async (req, res) => {
const dashboardStatus = await projectModel.dashboard();
res.status(200).json({ success: true, data: dashboardStatus });
},

getAllProjects: async (req, res) => {
try {
const projects = await projectModel.getAllProjects();
Expand Down
25 changes: 25 additions & 0 deletions src/models/projectModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,31 @@ const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

const projectModel = {

dashboard: async () => {
try {
// Count the total number of projects
const projectsCount = await prisma.projects.count();

// Count the total number of users
const usersCount = await prisma.users.count();

// Count the total number of comments
const commentsCount = await prisma.comments.count();

return {
projects: projectsCount,
users: usersCount,
comments: commentsCount,
};
} catch (error) {
console.error("Error fetching counts:", error);
throw error;
} finally {
await prisma.$disconnect();
}
},

getAllProjects: async () => {
try {
console.log("Fetching all projects...");
Expand Down
1 change: 1 addition & 0 deletions src/routes/projectRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require('express');
const router = express.Router();
const projectController = require('../controllers/projectController');

router.get('/dashboard', projectController.dashboard); // endpoint for getting total project, comments and users.
router.get('/projects', projectController.getAllProjects); // Endpoint to get all projects
router.get('/projects/:id', projectController.getProjectById); // Endpoint to get a specific project by ID
router.post('/addproject', projectController.addProject); // Endpoint to add a new project
Expand Down

0 comments on commit 6c82c52

Please sign in to comment.