From 5de6d8fba41c6e368103f31b2586468af4a423d7 Mon Sep 17 00:00:00 2001 From: Gowtham M Date: Mon, 10 Nov 2025 09:56:50 +0530 Subject: [PATCH] GWM : feedback changes --- app/controllers/dashboard.controller.js | 11 +++++--- app/controllers/establishment.controller.js | 15 ++++++++++- app/controllers/submission.controller.js | 30 +++++++++++++++++++++ app/models/establishment.model.js | 5 ++++ 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/app/controllers/dashboard.controller.js b/app/controllers/dashboard.controller.js index 853f652..6bb3171 100644 --- a/app/controllers/dashboard.controller.js +++ b/app/controllers/dashboard.controller.js @@ -74,13 +74,16 @@ exports.getEstablishmentDashboard = async (req, res) => { limit: 5, attributes: { include: [ + [ + Sequelize.literal(`( SELECT COUNT(*) FROM submission_products AS sp WHERE sp.submission_id = submission.id )`), + "product_count", + ], [ Sequelize.literal(`( - SELECT COUNT(*) - FROM submission_products AS sp - WHERE sp.submission_id = submission.id + SELECT survey_name FROM quarterly_windows_configuration_master AS QW + WHERE QW.quarter = submission.quarter AND QW.year = submission.year limit 1 )`), - "product_count", + "survey_name", ], ], }, diff --git a/app/controllers/establishment.controller.js b/app/controllers/establishment.controller.js index fde0f40..d639cb2 100644 --- a/app/controllers/establishment.controller.js +++ b/app/controllers/establishment.controller.js @@ -7,6 +7,7 @@ const EstablishmentProduct = db.EstablishmentProduct; const CityTown = db.CityTown; const Emirate = db.Emirate; const user = db.user; +const Product = db.Product; const ExcelJS = require("exceljs"); const { Op } = require("sequelize"); const { sendEmail } = require("../services/emailHelper"); @@ -455,7 +456,19 @@ exports.getEstablishmentById = async (req, res) => { model: user, as: "created_user", attributes: ["name"], - } + }, + { + model: EstablishmentProduct, + as: "establishment_products", + attributes: ["id", "establishment_id", "product_id"], + include: [ + { + model: Product, + as: "product", + attributes: ["product_name", "hs_code", "hs_description"], + }, + ], + }, ], }); diff --git a/app/controllers/submission.controller.js b/app/controllers/submission.controller.js index 8fa7172..42bc99b 100644 --- a/app/controllers/submission.controller.js +++ b/app/controllers/submission.controller.js @@ -361,6 +361,29 @@ exports.submissionList = async (req, res) => { return res.download(filePath); } + + // status summary count + const total = count; + const submitted = await Submission.count({ + where: { ...where, status: "Submitted" }, + include: [{model: Establishment,as: "establishment",where: establishmentWhere }] + }); + + const resubmitted = await Submission.count({ + where: { ...where, status: "Resubmitted" }, + include: [{model: Establishment,as: "establishment",where: establishmentWhere }] + }); + + const approved = await Submission.count({ + where: { ...where, status: "Approved" }, + include: [{model: Establishment,as: "establishment",where: establishmentWhere }] + }); + + const rejected = await Submission.count({ + where: { ...where, status: "Rejected" }, + include: [{model: Establishment,as: "establishment",where: establishmentWhere }] + }); + // 🔹 Paginated Response return res.status(200).json({ status: "success", @@ -371,6 +394,13 @@ exports.submissionList = async (req, res) => { limit: Number(limit), totalPages: Math.ceil(count / limit), }, + summary: { + total, + submitted, + resubmitted, + approved, + rejected + }, data: rows, }); } catch (err) { diff --git a/app/models/establishment.model.js b/app/models/establishment.model.js index 907a1d7..2526b7e 100644 --- a/app/models/establishment.model.js +++ b/app/models/establishment.model.js @@ -86,6 +86,11 @@ module.exports = (sequelize, DataTypes) => { as: "establishment" }); + Establishment.hasMany(models.EstablishmentProduct, { + foreignKey: "establishment_id", + as: "establishment_products" + }); + Establishment.belongsTo(models.CityTown, { foreignKey: 'establishment_city_town_id', as: 'establishment_city',