Skip to content

Commit 7a8fefd

Browse files
Merge pull request pradanvirudhunagar#24 from akshaykumar059004/main
Implementation: Fetch data for forms preview on dashboard (specific f…
2 parents 002f639 + cf83123 commit 7a8fefd

7 files changed

+70
-14
lines changed

controllers/dashboardData.controller.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const getTotalFormsStatusCount_sql = `
2020

2121
exports.getTotalFormsStatusCount = asyncHandler(async (req, res) => {
2222
const connection = await db.getConnection();
23-
const userId = req.params.userId;
23+
const userId = req.query.user_id;
24+
console.log(userId);
2425

2526
try {
2627
const [results] = await connection.execute(getTotalFormsStatusCount_sql, [userId]);
@@ -59,11 +60,11 @@ const getTodayFormsStatusCount_sql = `
5960
exports.getTodayFormsStatusCount = asyncHandler(async (req, res) => {
6061
const connection = await db.getConnection();
6162
const date = new Date();
62-
const userId = req.params.userId;
63+
const user_id = req.query.user_id;
6364
const today = new Date(date.getFullYear(), date.getMonth(), date.getDate()).toLocaleDateString('en-CA');// 'YYYY-MM-DD'
6465

6566
try {
66-
const [results] = await connection.execute(getTodayFormsStatusCount_sql, [userId, today]);
67+
const [results] = await connection.execute(getTodayFormsStatusCount_sql, [user_id, today]);
6768
if (results.length > 0) {
6869
res.json(results);
6970
} else {

controllers/landformData.controller.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const postLandformData_landdetails_sql = `INSERT INTO form_lands (
1515
patta, total_area, taluk, firka, revenue, crop_season, livestocks,
1616
sf_number, soil_type, land_to_benefit, area_benefited,
1717
type_of_work, any_other_works, p_contribution, f_contribution,
18-
total_est, date_of_app, date_of_ins
19-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,?)`;
18+
total_est, date_of_ins
19+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
2020

2121
const postLandformData_bankdetails_sql = `INSERT INTO bank_details (
2222
form_id, account_holder_name, account_number, bank_name,
@@ -99,7 +99,6 @@ exports.postLandformData = asyncHandler(async (req, res) => {
9999
safe(landformData.landDevelopment.pradanContribution),
100100
safe(landformData.landDevelopment.farmerContribution),
101101
safe(landformData.landDevelopment.totalEstimate),
102-
safe(today),
103102
safe(today)
104103
]);
105104

controllers/plantationformData.controller.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const postPlantationformData_plantation_details_sql = `INSERT INTO plantation_de
1515
patta, total_area, taluk, firka, revenue, crop_season, livestocks,
1616
sf_number, soil_type, land_to_benefit, date_of_ins,
1717
area_benefited_by_proposal, any_other_works, p_contribution, f_contribution,
18-
total_est, field_insp, date_of_app, plantaions
19-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
18+
total_est, field_insp, plantaions
19+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
2020

2121
const postPlantationformData_bankdetails_sql = `INSERT INTO bank_details (
2222
form_id, account_holder_name, account_number, bank_name,
@@ -102,7 +102,6 @@ exports.postPlantationformData = asyncHandler(async (req, res) => {
102102
safe(plantationformData.landDevelopment.farmerContribution),
103103
safe(plantationformData.landDevelopment.totalEstimate),
104104
safe(today),
105-
safe(today),
106105
safe(plantationformData.landDevelopment.workType2)
107106
]);
108107

controllers/pondformData.controller.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ const postPondformData_farm_pond_details_sql = `INSERT INTO farm_pond_details (
1515
patta, total_area, taluk, firka, revenue, crop_season, livestocks,
1616
sf_number, soil_type, land_to_benefit, date_of_ins, length, breadth,
1717
depth, volume, p_contribution, f_contribution, total_est, area_benefited,
18-
field_insp, date_of_app
19-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
18+
field_insp
19+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`;
2020

2121
const postLandformData_bankdetails_sql = `INSERT INTO bank_details (
2222
form_id, account_holder_name, account_number, bank_name,
@@ -102,7 +102,6 @@ exports.postPondformData = asyncHandler(async (req, res) => {
102102
safe(pondformData.landDevelopment.farmerContribution),
103103
safe(pondformData.landDevelopment.totalEstimate),
104104
safe(pondformData.landDevelopment.landBenefit),
105-
safe(today),
106105
safe(today)
107106
]);
108107

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const db = require("../configs/mysql_config");
2+
const asyncHandler = require("../middlewares/asyncHandler");
3+
4+
const getpreviewformsData_sql = `SELECT id, form_type, farmer_name, created_at, status FROM forms WHERE user_id = ?`;
5+
6+
exports.getpreviewformsData = asyncHandler(async (req, res) => {
7+
const connection = await db.getConnection();
8+
const user_id = req.query.user_id;
9+
// console.log(user_id);
10+
11+
try {
12+
const [results] = await connection.execute(getpreviewformsData_sql,[user_id]);
13+
14+
if (results.length > 0) {
15+
//console.log(results);
16+
return res.json(results);
17+
} else {
18+
return res.json(0);
19+
}
20+
} catch (err) {
21+
return res.status(500).json({ error: err.message });
22+
} finally {
23+
connection.release(); // Always release the connection
24+
}
25+
});
26+
27+
const getpreviewspecificformData_sql = ``;
28+
29+
exports.getpreviewspecificformData = asyncHandler(async (req, res) => {
30+
const connection = await db.getConnection();
31+
const form_id = req.query.form_id;
32+
//console.log(data.user_id);
33+
34+
try {
35+
const [results] = await connection.execute(getpreviewspecificformData_sql,[form_id]);
36+
37+
if (results.length > 0) {
38+
console.log(results);
39+
// return res.json(results);
40+
} else {
41+
return res.json(0);
42+
}
43+
} catch (err) {
44+
return res.status(500).json({ error: err.message });
45+
} finally {
46+
connection.release(); // Always release the connection
47+
}
48+
});

routes/dashboardData.route.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
const express = require("express");
22
const router = express.Router();
33
const { getTotalFormsStatusCount, getTodayFormsStatusCount } = require("../controllers/dashboardData.controller");
4+
const { getpreviewformsData, getpreviewspecificformData } = require("../controllers/previewformsData.controller");
45

56

6-
router.route('/getTotalFormsStatusCount/:userId').get(getTotalFormsStatusCount);
7-
router.route('/getTodayFormsStatusCount/:userId').get(getTodayFormsStatusCount);
7+
router.route('/getTotalFormsStatusCount').get(getTotalFormsStatusCount);
8+
router.route('/getTodayFormsStatusCount').get(getTodayFormsStatusCount);
9+
10+
//forms fetch for preview
11+
router.route('/getpreviewformsData').get(getpreviewformsData);
12+
router.route('/getpreviewspecificformData').get(getpreviewspecificformData);
813

914
module.exports = router;

routes/formData.route.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ const {postLandformData} = require("../controllers/landformData.controller");
44
const {postPondformData} = require("../controllers/pondformData.controller");
55
const {postPlantationformData} = require("../controllers/plantationformData.controller");
66

7+
8+
//forms submission routes
79
router.route('/postLandformData').post(postLandformData);
810
router.route('/postPondformData').post(postPondformData);
911
router.route('/postPlantationformData').post(postPlantationformData);
1012

13+
//forms fetch routes
14+
15+
1116
module.exports = router;

0 commit comments

Comments
 (0)