-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cc91e43
commit 5ba4822
Showing
4 changed files
with
58 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const express = require("express"); | ||
const router = express.Router(); | ||
const { check, query, validationResult } = require("express-validator"); | ||
const loggedIn = require("../../middleware/auth"); | ||
const TimeTable = require("../../models/TimeTable"); | ||
const Student = require("../../models/Student"); | ||
const Login = require("../../models/Login"); | ||
|
||
const mscBranches = ["BIO", "CHEM", "ECO", "MATH", "PHY"]; | ||
|
||
router.get("/", [], async (req, res) => { | ||
try { | ||
let nLogins = await Login.countDocuments(); | ||
let userLogins = await Login.find({}, "-_id -__v"); | ||
let nUniqueLogins = (await Login.find().distinct("userId")).length; | ||
let timetablesCreated = await TimeTable.find({}, "date").populate( | ||
"ownerId", | ||
"-_id branch year" | ||
); | ||
timetablesCreated = timetablesCreated.map(function (tt) { | ||
// null check | ||
if (tt.ownerId) { | ||
let branches = tt.ownerId.branch; | ||
|
||
if (branches.length == 2) { | ||
if (mscBranches.includes(branches[0])) { | ||
tt.ownerId.branch = [branches[0]]; | ||
} else if (mscBranches.includes(branches[1])) { | ||
tt.ownerId.branch = [branches[1]]; | ||
} else { | ||
tt.ownerId.branch = [branches[0]]; | ||
} | ||
} | ||
} | ||
return tt; | ||
}); | ||
|
||
res.status(200).json({ | ||
nLogins: nLogins, | ||
nUniqueLogin: nUniqueLogins, | ||
userLogins: userLogins, | ||
timetablesCreated: timetablesCreated | ||
}); | ||
} catch (err) { | ||
console.error(err.message); | ||
res.status(500).send("Server error"); | ||
} | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters