aboutsummaryrefslogtreecommitdiff
path: root/interface/controllers/citizens.controller.js
diff options
context:
space:
mode:
authorBobby <[email protected]>2022-05-01 01:01:22 -0400
committerBobby <[email protected]>2022-05-01 01:01:22 -0400
commitc79afe469347ce4f0cffa1ba268939fd00662e81 (patch)
tree71ed919b888e83fb49d619d1ba338dcba43b245c /interface/controllers/citizens.controller.js
parenta31f92a2015fd5c5b4166c8c2fee42c3ec461ca8 (diff)
downloadWelfare-Schemes-DMQL-c79afe469347ce4f0cffa1ba268939fd00662e81.tar.xz
Welfare-Schemes-DMQL-c79afe469347ce4f0cffa1ba268939fd00662e81.zip
added gender distribution to main page
Diffstat (limited to 'interface/controllers/citizens.controller.js')
-rw-r--r--interface/controllers/citizens.controller.js27
1 files changed, 21 insertions, 6 deletions
diff --git a/interface/controllers/citizens.controller.js b/interface/controllers/citizens.controller.js
index 64522b1..b50ee74 100644
--- a/interface/controllers/citizens.controller.js
+++ b/interface/controllers/citizens.controller.js
@@ -1,11 +1,26 @@
const db = require("../models");
const citizens = db.citizens;
-const op = db.Sequelize.Op;
// Retrieve all citizens from the database. Limit the number of citizens returned to 10.
exports.findXCitizens = () => {
- const limit = 10;
- return citizens.findAll({
- limit: limit
- });
-}
+ const limit = 10;
+ return citizens.findAll({
+ limit: limit,
+ });
+};
+
+// Get total number of male and female citizens
+exports.findGenderDistribution = () => {
+ // group by the 'gender' column
+
+ /**
+ * This code is equivalent to the following SQL query:
+ * select count(gender), gender from citizens group by gender;
+ */
+
+ return citizens.findAll({
+ group: ["gender"],
+ attributes: ["gender", [db.sequelize.fn("COUNT", "gender"), "genderCount"]],
+ raw: true
+ });
+};