This commit is contained in:
rgrgogu
2026-05-07 23:35:22 +08:00
parent 09660d7503
commit 58ccecd28a
10 changed files with 370 additions and 53 deletions
+5 -9
View File
@@ -147,26 +147,22 @@ function modelToAttributes(model, { jsonbSchemas = {}, exclude = [], timestampLa
});
}
// ─── Sort all fields globally by order ─────────────────────────────────────
attributes.sort((a, b) => (a.order ?? Infinity) - (b.order ?? Infinity));
// ─── Strip order from final output (frontend doesn't need it) ──────────────
const sorted = attributes.map(({ order: _, ...rest }) => rest);
// ── Audit fields in correct sequence ────────────────────────────────────────
for (const { field, type } of auditSequence) {
for (const { field, type, order } of auditSequence) {
if (exclude.includes(field)) continue;
if (!rawAttrs[field]) continue; // skip if field doesn't exist on model
sorted.push({
attributes.push({
name: defaultTimestampLabels[field],
type,
field,
order,
options: resolveOptions(rawAttrs[field]?.type),
});
}
return sorted;
// ── Sort by order — DO NOT strip order here, paginate.util does it ───────────
return attributes.sort((a, b) => (a.order ?? Infinity) - (b.order ?? Infinity));
}
module.exports = { modelToAttributes };