Created_by name added in the establishment list api
This commit is contained in:
parent
ce45de6a27
commit
4cc2b1c1d0
@ -320,24 +320,38 @@ exports.getAllEstablishments = async (req, res) => {
|
||||
}
|
||||
|
||||
// Fetch Data
|
||||
const data = await Establishment.findAll({
|
||||
where: whereClause,
|
||||
attributes: {
|
||||
include: [
|
||||
[
|
||||
Sequelize.literal(`(SELECT COUNT(*) FROM establishment_products ep WHERE ep.establishment_id = establishments.id)`),"product_count" ]
|
||||
const data = await Establishment.findAll({
|
||||
where: whereClause,
|
||||
attributes: {
|
||||
include: [
|
||||
[
|
||||
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: [
|
||||
{ model: CityTown, as: "establishment_city", attributes: ["name"] },
|
||||
{ model: Emirate, as: "establishment_emirate", attributes: ["name"] },
|
||||
{ model: CityTown, as: "corporate_city", attributes: ["name"] },
|
||||
{ model: Emirate, as: "corporate_emirate", attributes: ["name"] },
|
||||
{ model: user, as: "created_user", attributes: ["name"] },
|
||||
],
|
||||
order: [[sort_by, sort_order]],
|
||||
...(exportType ? {} : { limit, offset }), // pagination only when not exporting
|
||||
});
|
||||
},
|
||||
include: [
|
||||
{ model: CityTown, as: "establishment_city", attributes: ["name"] },
|
||||
{ model: Emirate, as: "establishment_emirate", attributes: ["name"] },
|
||||
{ model: CityTown, as: "corporate_city", attributes: ["name"] },
|
||||
{ model: Emirate, as: "corporate_emirate", attributes: ["name"] },
|
||||
{ model: user, as: "created_user", attributes: ["name"] },
|
||||
],
|
||||
order: [[sort_by, sort_order]],
|
||||
...(exportType ? {} : { limit, offset }),
|
||||
});
|
||||
|
||||
// If export = excel → generate file
|
||||
if (exportType && exportType.toLowerCase() === "excel") {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user