2023-09-21 14:00:04 +00:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
|
2024-10-14 06:49:01 +00:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @param {object} param0
|
2024-12-06 10:31:24 +00:00
|
|
|
* @param {import("../../types").DSQL_FieldSchemaType[]} param0.tableInfoArray
|
2024-10-14 06:49:01 +00:00
|
|
|
* @returns
|
|
|
|
*/
|
2023-09-21 14:00:04 +00:00
|
|
|
module.exports = function supplementTable({ tableInfoArray }) {
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
defaultFields.forEach((field) => {
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
/** ****************************************************************************** */
|
|
|
|
/** ****************************************************************************** */
|