mirror of
https://github.com/rgrgogu/new_starr.git
synced 2026-09-27 00:12:54 +08:00
Adjusted
This commit is contained in:
@@ -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 };
|
||||
Reference in New Issue
Block a user