This commit is contained in:
rgrgogu
2026-05-14 12:59:42 +08:00
parent 06c4286c4a
commit c3663572ae
12 changed files with 570 additions and 536 deletions
+13 -10
View File
@@ -89,7 +89,7 @@ function flattenJsonb(jsonbSchema = {}, prefix = "", exclude = []) {
* @param {string[]} exclude - field names to exclude (e.g. ["password", "otp_code"])
* @returns {Array} attributes array
*/
function modelToAttributes(model, { jsonbSchemas = {}, exclude = [], timestampLabels = {} } = {}) {
function modelToAttributes(model, { jsonbSchemas = {}, exclude = [], timestampLabels = {}, context = "" } = {}) {
const rawAttrs = model.rawAttributes || model.tableAttributes;
const attributes = [];
@@ -113,14 +113,14 @@ function modelToAttributes(model, { jsonbSchemas = {}, exclude = [], timestampLa
// Ordered audit sequence
const auditSequence = [
{ field: 'updatedAt', type: 'date' },
{ field: 'modifiedAt', type: 'date' },
{ field: 'updatedBy', type: 'text' },
{ field: 'createdAt', type: 'date' },
{ field: 'createdBy', type: 'text' },
{ field: 'deletedAt', type: 'date' },
{ field: 'deletedBy', type: 'text' },
];
{ field: "updatedAt", type: "date", hiddenOnList: false, hiddenOnArchived: true },
{ field: "modifiedAt", type: "date", hiddenOnList: false, hiddenOnArchived: true },
{ field: "updatedBy", type: "text", hiddenOnList: false, hiddenOnArchived: true },
{ field: "createdAt", type: "date", hiddenOnList: false, hiddenOnArchived: true },
{ field: "createdBy", type: "text", hiddenOnList: false, hiddenOnArchived: true },
{ field: "deletedAt", type: "date", hiddenOnList: true, hiddenOnArchived: false },
{ field: "deletedBy", type: "text", hiddenOnList: true, hiddenOnArchived: false },
];
// ── Normal fields (excluding audit) ─────────────────────────────────────────
for (const [field, def] of Object.entries(rawAttrs)) {
@@ -148,15 +148,18 @@ function modelToAttributes(model, { jsonbSchemas = {}, exclude = [], timestampLa
}
// ── Audit fields in correct sequence ────────────────────────────────────────
for (const { field, type, order } of auditSequence) {
for (const { field, type, order, hiddenOnList, hiddenOnArchived } of auditSequence) {
if (exclude.includes(field)) continue;
if (!rawAttrs[field]) continue; // skip if field doesn't exist on model
const isArchived = context === "archived";
attributes.push({
name: defaultTimestampLabels[field],
type,
field,
order,
hidden: isArchived ? hiddenOnArchived : hiddenOnList,
options: resolveOptions(rawAttrs[field]?.type),
});
}