datasquirel/package-shared/shell/utils/supplementTable.ts
2025-01-10 20:10:28 +01:00

53 lines
1.7 KiB
TypeScript
Executable File

import { DSQL_FieldSchemaType } from "../../types";
type Param = {
tableInfoArray: DSQL_FieldSchemaType[];
};
/**
* # Supplement Table
*/
export default function supplementTable({ tableInfoArray }: Param) {
/**
* Format tableInfoArray
*
* @description Format tableInfoArray
*/
let finalTableArray = tableInfoArray;
const defaultFields = require("../../../package-shared/data/defaultFields.json");
////////////////////////////////////////
let primaryKeyExists = finalTableArray.filter(
(_field) => _field.primaryKey
);
////////////////////////////////////////
defaultFields.forEach((field: any) => {
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;
}
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */