diff --git a/server/controllers/routes/admin/stats.js b/server/controllers/routes/admin/stats.js index 408a99e0..7ae55546 100644 --- a/server/controllers/routes/admin/stats.js +++ b/server/controllers/routes/admin/stats.js @@ -1,11 +1,16 @@ const { getCohorts } = require('../../../database/queries'); +const { getAlumniQuery } = require('../../../database/queries'); +const { getAllProjects } = require('../../../database/queries'); const getStats = async (req, res, next) => { try { const cohorts = await getCohorts(); const cohortsCount = cohorts.rowCount; - const projectsCount = 16; - const studentsCount = 45; + const projects = await getAllProjects(); + const projectsCount = projects.rowCount; + const students = await getAlumniQuery(); + const studentsCount = students.rowCount; + res.json({ StatusCode: 200, data: [ diff --git a/server/database/queries/index.js b/server/database/queries/index.js index ed715406..d48ece23 100644 --- a/server/database/queries/index.js +++ b/server/database/queries/index.js @@ -14,6 +14,7 @@ const { deleteProject, getCohortProjectsQuery, getProjects, + getAllProjects, } = require('./project'); module.exports = { @@ -31,4 +32,5 @@ module.exports = { getProjectById, deleteProject, getProjects, + getAllProjects, }; diff --git a/server/database/queries/project/getAllProjects.js b/server/database/queries/project/getAllProjects.js new file mode 100644 index 00000000..09894894 --- /dev/null +++ b/server/database/queries/project/getAllProjects.js @@ -0,0 +1,5 @@ +const connection = require('../../config/connection'); + +const getAllProjects = () => connection.query('SELECT * FROM project'); + +module.exports = getAllProjects; diff --git a/server/database/queries/project/index.js b/server/database/queries/project/index.js index 9d9ba6cd..cf94683b 100644 --- a/server/database/queries/project/index.js +++ b/server/database/queries/project/index.js @@ -4,6 +4,7 @@ const getCohortProjectsQuery = require('./getCohortProjects'); const editProjectQuery = require('./editProject'); const getProjectById = require('./getProjectById'); const deleteProject = require('./deleteProject'); +const getAllProjects = require('./getAllProjects'); module.exports = { getProjects, @@ -12,4 +13,5 @@ module.exports = { editProjectQuery, getProjectById, deleteProject, + getAllProjects, }; diff --git a/test/index.test.js b/test/index.test.js index afe6131a..e2ff21cd 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -392,8 +392,10 @@ describe('Get stats', () => { .expect('Content-Type', /json/) .end((err, res) => { if (err) return done(err); - const { data } = res.body; + const { data } = res.body;console.log(data) expect(data[0].numOfCohorts).toBe(2); + expect(data[1].numOfProjects).toBe(7); + expect(data[2].numOfStudents).toBe(2); done(); }); });