Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-07-12 12:39:17 +08:00
parent 82ea9c77c4
commit ea3e82e54c
47 changed files with 1301 additions and 481 deletions
+10 -5
View File
@@ -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)) {