dsql-admin/dsql-app/package-shared/shell/utils/supplementTable.ts

53 lines
1.7 KiB
TypeScript
Raw Normal View History

2025-01-13 08:00:21 +00:00
import { DSQL_FieldSchemaType } from "../../types";
2024-12-06 13:24:26 +00:00
2025-01-13 08:00:21 +00:00
type Param = {
tableInfoArray: DSQL_FieldSchemaType[];
};
2024-12-06 13:24:26 +00:00
/**
2025-01-13 08:00:21 +00:00
* # Supplement Table
2024-12-06 13:24:26 +00:00
*/
2025-01-13 08:00:21 +00:00
export default function supplementTable({ tableInfoArray }: Param) {
2024-12-06 13:24:26 +00:00
/**
* Format tableInfoArray
*
* @description Format tableInfoArray
*/
let finalTableArray = tableInfoArray;
const defaultFields = require("../../../package-shared/data/defaultFields.json");
////////////////////////////////////////
let primaryKeyExists = finalTableArray.filter(
(_field) => _field.primaryKey
);
////////////////////////////////////////
2025-01-13 08:00:21 +00:00
defaultFields.forEach((field: any) => {
2024-12-06 13:24:26 +00:00
let fieldExists = finalTableArray.filter(
(_field) => _field.fieldName === field.fieldName
);
if (fieldExists && fieldExists[0]) {
return;
} else if (field.fieldName === "id" && !primaryKeyExists[0]) {
finalTableArray.unshift(field);
} else {
finalTableArray.push(field);
}
});
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
return finalTableArray;
2025-01-13 08:00:21 +00:00
}
2024-12-06 13:24:26 +00:00
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */