This commit is contained in:
2025-12-16 11:19:06 +01:00
parent 14ea760373
commit 0d9f313dc0
5 changed files with 27 additions and 7 deletions
@@ -7,12 +7,13 @@ exports.default = grabParsedValue;
const sanitize_html_1 = __importDefault(require("sanitize-html"));
const sanitizeHtmlOptions_1 = __importDefault(require("../html/sanitizeHtmlOptions"));
const encrypt_1 = __importDefault(require("../../dsql/encrypt"));
const numberfy_1 = __importDefault(require("../../../utils/numberfy"));
/**
* # Update DB Function
* @description
*/
function grabParsedValue({ value, tableSchema, encryptionKey, encryptionSalt, dataKey, }) {
var _a, _b, _c;
var _a, _b, _c, _d;
let newValue = value;
const targetFieldSchema = tableSchema
? (_a = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields) === null || _a === void 0 ? void 0 : _a.find((field) => field.fieldName === dataKey)
@@ -37,6 +38,10 @@ function grabParsedValue({ value, tableSchema, encryptionKey, encryptionSalt, da
!(value === null || value === void 0 ? void 0 : value.match(/./))) {
newValue = "";
}
if (((_c = targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.dataType) === null || _c === void 0 ? void 0 : _c.match(/int$|decimal|float|double/i)) &&
typeof value == "string") {
newValue = (0, numberfy_1.default)(value);
}
if (targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.encrypted) {
newValue =
(0, encrypt_1.default)({
@@ -60,7 +65,7 @@ function grabParsedValue({ value, tableSchema, encryptionKey, encryptionSalt, da
newValue = undefined;
}
if (typeof newValue === "boolean" ||
((_c = targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.dataType) === null || _c === void 0 ? void 0 : _c.match(/boolean/i))) {
((_d = targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.dataType) === null || _d === void 0 ? void 0 : _d.match(/boolean/i))) {
newValue = newValue ? 1 : 0;
}
return newValue;
+3 -2
View File
@@ -261,10 +261,11 @@ function sqlGenerator({ tableName, genObject, dbFullName, count }) {
}
return genSqlSrchStr({ queryObj, field, join: genObject === null || genObject === void 0 ? void 0 : genObject.join });
});
const isSearchStr = (sqlSearhString === null || sqlSearhString === void 0 ? void 0 : sqlSearhString[0]) && sqlSearhString.find((str) => str);
const cleanedUpSearchStr = sqlSearhString === null || sqlSearhString === void 0 ? void 0 : sqlSearhString.filter((str) => typeof str == "string");
const isSearchStr = (cleanedUpSearchStr === null || cleanedUpSearchStr === void 0 ? void 0 : cleanedUpSearchStr[0]) && cleanedUpSearchStr.find((str) => str);
if (isSearchStr) {
const stringOperator = (genObject === null || genObject === void 0 ? void 0 : genObject.searchOperator) || "AND";
queryString += ` WHERE ${sqlSearhString.join(` ${stringOperator} `)}`;
queryString += ` WHERE ${cleanedUpSearchStr.join(` ${stringOperator} `)}`;
}
if ((genObject === null || genObject === void 0 ? void 0 : genObject.fullTextSearch) && fullTextSearchStr && fullTextMatchStr) {
queryString += `${isSearchStr ? " AND" : " WHERE"} ${fullTextMatchStr}`;