GWM : feedback changes
This commit is contained in:
parent
83fabc7292
commit
5de6d8fba4
@ -74,13 +74,16 @@ exports.getEstablishmentDashboard = async (req, res) => {
|
|||||||
limit: 5,
|
limit: 5,
|
||||||
attributes: {
|
attributes: {
|
||||||
include: [
|
include: [
|
||||||
|
[
|
||||||
|
Sequelize.literal(`( SELECT COUNT(*) FROM submission_products AS sp WHERE sp.submission_id = submission.id )`),
|
||||||
|
"product_count",
|
||||||
|
],
|
||||||
[
|
[
|
||||||
Sequelize.literal(`(
|
Sequelize.literal(`(
|
||||||
SELECT COUNT(*)
|
SELECT survey_name FROM quarterly_windows_configuration_master AS QW
|
||||||
FROM submission_products AS sp
|
WHERE QW.quarter = submission.quarter AND QW.year = submission.year limit 1
|
||||||
WHERE sp.submission_id = submission.id
|
|
||||||
)`),
|
)`),
|
||||||
"product_count",
|
"survey_name",
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|||||||
@ -7,6 +7,7 @@ const EstablishmentProduct = db.EstablishmentProduct;
|
|||||||
const CityTown = db.CityTown;
|
const CityTown = db.CityTown;
|
||||||
const Emirate = db.Emirate;
|
const Emirate = db.Emirate;
|
||||||
const user = db.user;
|
const user = db.user;
|
||||||
|
const Product = db.Product;
|
||||||
const ExcelJS = require("exceljs");
|
const ExcelJS = require("exceljs");
|
||||||
const { Op } = require("sequelize");
|
const { Op } = require("sequelize");
|
||||||
const { sendEmail } = require("../services/emailHelper");
|
const { sendEmail } = require("../services/emailHelper");
|
||||||
@ -455,7 +456,19 @@ exports.getEstablishmentById = async (req, res) => {
|
|||||||
model: user,
|
model: user,
|
||||||
as: "created_user",
|
as: "created_user",
|
||||||
attributes: ["name"],
|
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"],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|||||||
@ -361,6 +361,29 @@ exports.submissionList = async (req, res) => {
|
|||||||
return res.download(filePath);
|
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
|
// 🔹 Paginated Response
|
||||||
return res.status(200).json({
|
return res.status(200).json({
|
||||||
status: "success",
|
status: "success",
|
||||||
@ -371,6 +394,13 @@ exports.submissionList = async (req, res) => {
|
|||||||
limit: Number(limit),
|
limit: Number(limit),
|
||||||
totalPages: Math.ceil(count / limit),
|
totalPages: Math.ceil(count / limit),
|
||||||
},
|
},
|
||||||
|
summary: {
|
||||||
|
total,
|
||||||
|
submitted,
|
||||||
|
resubmitted,
|
||||||
|
approved,
|
||||||
|
rejected
|
||||||
|
},
|
||||||
data: rows,
|
data: rows,
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@ -86,6 +86,11 @@ module.exports = (sequelize, DataTypes) => {
|
|||||||
as: "establishment"
|
as: "establishment"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Establishment.hasMany(models.EstablishmentProduct, {
|
||||||
|
foreignKey: "establishment_id",
|
||||||
|
as: "establishment_products"
|
||||||
|
});
|
||||||
|
|
||||||
Establishment.belongsTo(models.CityTown, {
|
Establishment.belongsTo(models.CityTown, {
|
||||||
foreignKey: 'establishment_city_town_id',
|
foreignKey: 'establishment_city_town_id',
|
||||||
as: 'establishment_city',
|
as: 'establishment_city',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user