From 40eac9bcc99f0dc0139a9356464df66e9cf5c7dc Mon Sep 17 00:00:00 2001 From: jmreddy2106 Date: Tue, 3 May 2022 12:39:38 -0400 Subject: added edit functionality to citizens --- interface/config/db.config.js | 2 +- interface/controllers/citizens.controller.js | 30 +++++- interface/models/citizens.model.js | 2 + interface/views/citizens.ejs | 137 ++++++++++++++++++++++++--- interface/views/partials/scripts.ejs | 8 ++ 5 files changed, 160 insertions(+), 19 deletions(-) (limited to 'interface') diff --git a/interface/config/db.config.js b/interface/config/db.config.js index ea90d0c..622d5f5 100644 --- a/interface/config/db.config.js +++ b/interface/config/db.config.js @@ -3,7 +3,7 @@ module.exports = { // The name of the database database: process.env.DATABASE, // The username used to connect to the database - username: process.env.USERNAME, + username: process.env.USER, // The password used to connect to the database password: process.env.PASSWORD, // The dialect of the database you are connecting to diff --git a/interface/controllers/citizens.controller.js b/interface/controllers/citizens.controller.js index b50ee74..9eaf153 100644 --- a/interface/controllers/citizens.controller.js +++ b/interface/controllers/citizens.controller.js @@ -1,21 +1,43 @@ +const req = require("express/lib/request"); const db = require("../models"); const citizens = db.citizens; +const village_master = db.village_master; +const {QueryTypes} = require('sequelize'); +const { sequelize } = require("../models"); + // Retrieve all citizens from the database. Limit the number of citizens returned to 10. exports.findXCitizens = () => { + /** + * select c.first_name, c.last_name, c.address, c.mobile_num, c.dob, c.gender, c.marital_status, v.village_name + from citizens c + join village_master v + on c.village_id = v.village_id + limit 10 + */ const limit = 10; - return citizens.findAll({ - limit: limit, - }); + // Raw query in Sequelize + + query = `select c.citizen_id, c.first_name, c.last_name, c.address, c.mobile_num, c.dob, c.gender, c.marital_status, c.village_id, v.village_name + from citizens c + join village_master v + on c.village_id = v.village_id + limit 10` + + return sequelize.query(query, { type: QueryTypes.SELECT }) }; + + + + // 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; + * select count(gender), gender from citizens group by gender ; */ return citizens.findAll({ diff --git a/interface/models/citizens.model.js b/interface/models/citizens.model.js index f6310b0..5096417 100644 --- a/interface/models/citizens.model.js +++ b/interface/models/citizens.model.js @@ -1,3 +1,4 @@ + module.exports = (Sequelize, sequelize) => { const Citizens = sequelize.define("citizens", { citizen_id: { @@ -61,5 +62,6 @@ module.exports = (Sequelize, sequelize) => { }, }, }); + return Citizens; }; diff --git a/interface/views/citizens.ejs b/interface/views/citizens.ejs index 97c98fa..d11b4f5 100644 --- a/interface/views/citizens.ejs +++ b/interface/views/citizens.ejs @@ -1,51 +1,160 @@ + + + + <%- include('partials/head') %> + + <%- include('partials/navbar') %> - +
- + - + - - - - + + + + <% for(var i=0; i < citizens.length; i++) { %> - + - - - - - + + + + + <% } %>
Citizen ID First NameMiddle Name Last Name Address Mobile Number Date of Birth Gender Marital StatusDisabledDisabled PercentageCasteVillage IDVillage Name
<%= citizens[i].citizen_id %> <%= citizens[i].first_name %> + <%= citizens[i].last_name %> <%= citizens[i].address %> <%= citizens[i].mobile_num %> <%= citizens[i].dob %> <%= citizens[i].gender %> <%= citizens[i].marital_status %><%= citizens[i].disabled %><%= citizens[i].disbaled_percentage %><%= citizens[i].caste %><%= citizens[i].village_id %><%= citizens[i].village_name %> +
+
Edit
+ +
+
<%- include('partials/scripts') %> + diff --git a/interface/views/partials/scripts.ejs b/interface/views/partials/scripts.ejs index a90467a..02a61ab 100644 --- a/interface/views/partials/scripts.ejs +++ b/interface/views/partials/scripts.ejs @@ -7,3 +7,11 @@ + \ No newline at end of file -- cgit v1.2.3