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