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