mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -30,25 +30,30 @@ const getFieldValues = (Model, logTag, options = {}) => async (req, res) => {
|
||||
return R.error(res, "Invalid or restricted field.", 400);
|
||||
|
||||
if (auditByFields.includes(field)) {
|
||||
// Filtering must match the audit column's real (bigint) id — returning
|
||||
// just the display name here previously made buildWhere() compare a
|
||||
// name string against the raw id column via a text cast, which can
|
||||
// never match. Carry both: `value` (id) is what gets filtered on,
|
||||
// `label` (full_name) is what the filter sheet displays.
|
||||
const tableName = Model.getTableName();
|
||||
const [rows] = selfJoin
|
||||
? await sequelize.query(`
|
||||
SELECT DISTINCT u2."personal_info"->'name'->>'full_name' AS value
|
||||
SELECT DISTINCT u1."${field}" AS value, u2."personal_info"->'name'->>'full_name' AS label
|
||||
FROM "${tableName}" u1
|
||||
JOIN "${tableName}" u2 ON u2.user_id = u1."${field}"
|
||||
WHERE u1."${field}" IS NOT NULL
|
||||
AND u2."personal_info"->'name'->>'full_name' IS NOT NULL
|
||||
ORDER BY value ASC
|
||||
ORDER BY label ASC
|
||||
`)
|
||||
: await sequelize.query(`
|
||||
SELECT DISTINCT u."personal_info"->'name'->>'full_name' AS value
|
||||
SELECT DISTINCT t."${field}" AS value, u."personal_info"->'name'->>'full_name' AS label
|
||||
FROM "${tableName}" t
|
||||
JOIN users u ON u.user_id = t."${field}"
|
||||
WHERE t."${field}" IS NOT NULL
|
||||
AND u."personal_info"->'name'->>'full_name' IS NOT NULL
|
||||
ORDER BY value ASC
|
||||
ORDER BY label ASC
|
||||
`);
|
||||
return R.success(res, "Field values retrieved.", rows.map((r) => r.value).filter(Boolean));
|
||||
return R.success(res, "Field values retrieved.", rows.filter((r) => r.label));
|
||||
}
|
||||
|
||||
if (dateFields.includes(field)) {
|
||||
|
||||
Reference in New Issue
Block a user