mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
@@ -29,6 +29,19 @@ const getFieldValues = (Model, logTag, options = {}) => async (req, res) => {
|
||||
if (!allowedFields.includes(field) && !dateFields.includes(field))
|
||||
return R.error(res, "Invalid or restricted field.", 400);
|
||||
|
||||
// ─── ENUM / BOOLEAN fields — return the canonical value set, not a DISTINCT
|
||||
// scan of current rows. A DISTINCT query silently omits valid values
|
||||
// that just don't happen to exist yet (e.g. is_banned when nobody is
|
||||
// currently banned), which produces an incomplete filter picklist.
|
||||
const rawType = Model.rawAttributes[field]?.type;
|
||||
const typeKey = rawType?.constructor?.key || rawType?.key;
|
||||
if (typeKey === "ENUM") {
|
||||
return R.success(res, "Field values retrieved.", rawType.values ?? []);
|
||||
}
|
||||
if (typeKey === "BOOLEAN") {
|
||||
return R.success(res, "Field values retrieved.", ["true", "false"]);
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
@@ -95,6 +95,15 @@ async function paginate(model, req, {
|
||||
const jsonbExclude = excludeAttributes.filter((f) => f.includes('.'));
|
||||
const jsonbAttr = jsonbColumn ? excludeJsonbPaths(jsonbColumn, jsonbExclude) : null;
|
||||
|
||||
// The stripped jsonbAttr projection is aliased to the same name as the raw
|
||||
// column (e.g. "personal_info") — without excluding the raw column too, it
|
||||
// gets selected twice under the same alias, which Postgres/CockroachDB
|
||||
// accept in a plain SELECT but reject as ambiguous the moment that alias is
|
||||
// referenced in ORDER BY (e.g. sorting a jsonb-path column).
|
||||
if (jsonbAttr && jsonbColumn && !topLevelExclude.includes(jsonbColumn)) {
|
||||
topLevelExclude.push(jsonbColumn);
|
||||
}
|
||||
|
||||
const attributes = modelToAttributes(model, { exclude: excludeAttributes, jsonbSchemas, context });
|
||||
const ALLOWED_FIELDS = attributes.map((a) => a.field);
|
||||
const computedFieldKeys = computedAttributes.map((c) => c.key);
|
||||
|
||||
Reference in New Issue
Block a user