GWM : feedback changes

This commit is contained in:
Gowtham M 2025-11-10 09:56:50 +05:30
parent 83fabc7292
commit 5de6d8fba4
4 changed files with 56 additions and 5 deletions

View File

@ -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",
],
],
},

View File

@ -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"],
},
],
},
],
});

View File

@ -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) {

View File

@ -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',