Created_by name added in the establishment list api

This commit is contained in:
unknown 2025-11-21 16:35:19 +05:30
parent ce45de6a27
commit 4cc2b1c1d0

View File

@ -325,7 +325,21 @@ exports.getAllEstablishments = async (req, res) => {
attributes: {
include: [
[
Sequelize.literal(`(SELECT COUNT(*) FROM establishment_products ep WHERE ep.establishment_id = establishments.id)`),"product_count" ]
Sequelize.literal(`(
SELECT COUNT(*)
FROM establishment_products ep
WHERE ep.establishment_id = establishments.id
)`),
"product_count"
],
[
Sequelize.literal(`(
SELECT name
FROM admin_users au
WHERE au.id = establishments.created_by
)`),
"created_by_name"
]
]
},
include: [
@ -336,7 +350,7 @@ exports.getAllEstablishments = async (req, res) => {
{ model: user, as: "created_user", attributes: ["name"] },
],
order: [[sort_by, sort_order]],
...(exportType ? {} : { limit, offset }), // pagination only when not exporting
...(exportType ? {} : { limit, offset }),
});
// If export = excel → generate file