diff options
| author | Bobby <[email protected]> | 2022-05-01 01:02:38 -0400 |
|---|---|---|
| committer | GitHub <[email protected]> | 2022-05-01 01:02:38 -0400 |
| commit | b0b1938f0e2ae2d159f0a616f8043d0b7f24f2eb (patch) | |
| tree | 71ed919b888e83fb49d619d1ba338dcba43b245c /interface/controllers/citizens.controller.js | |
| parent | fd8acf8d1b04368763a97d1452565aa71dcc118a (diff) | |
| parent | d527bddaeb3083d2a5ec787626e512eb45d3a967 (diff) | |
| download | Welfare-Schemes-DMQL-b0b1938f0e2ae2d159f0a616f8043d0b7f24f2eb.tar.xz Welfare-Schemes-DMQL-b0b1938f0e2ae2d159f0a616f8043d0b7f24f2eb.zip | |
Merge pull request #4 from luciferreeves/main
Main page changes
Diffstat (limited to 'interface/controllers/citizens.controller.js')
| -rw-r--r-- | interface/controllers/citizens.controller.js | 27 |
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 + }); +}; |
