Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dashboard status #24

Merged
merged 1 commit into from
Jan 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading