This commit is contained in:
Tben 2023-07-07 16:45:55 +01:00
parent d0a64858ec
commit 152fd56301
2 changed files with 24 additions and 21 deletions

View File

@ -95,29 +95,33 @@ module.exports = async function add({ dbFullName, tableName, data, tableSchema,
let insertValuesArray = []; let insertValuesArray = [];
for (let i = 0; i < dataKeys.length; i++) { for (let i = 0; i < dataKeys.length; i++) {
const dataKey = dataKeys[i]; try {
let value = data[dataKey]; const dataKey = dataKeys[i];
let value = data[dataKey];
const targetFieldSchemaArray = tableSchema ? tableSchema?.fields.filter((field) => field.fieldName === dataKey) : null; const targetFieldSchemaArray = tableSchema ? tableSchema?.fields.filter((field) => field.fieldName === dataKey) : null;
const targetFieldSchema = targetFieldSchemaArray && targetFieldSchemaArray[0] ? targetFieldSchemaArray[0] : null; const targetFieldSchema = targetFieldSchemaArray && targetFieldSchemaArray[0] ? targetFieldSchemaArray[0] : null;
if (!value) continue; if (!value) continue;
if (targetFieldSchema?.encrypted) { if (targetFieldSchema?.encrypted) {
value = encrypt({ data: value, encryptionKey, encryptionSalt }); value = encrypt({ data: value, encryptionKey, encryptionSalt });
}
if (targetFieldSchema?.richText) {
value = sanitizeHtml(value, sanitizeHtmlOptions);
}
insertKeysArray.push("`" + dataKey + "`");
if (typeof value === "object") {
value = JSON.stringify(value);
}
insertValuesArray.push(value);
} catch (error) {
console.log("Error in add DB try catch block =>", error.message);
} }
if (targetFieldSchema?.richText) {
value = sanitizeHtml(value, sanitizeHtmlOptions).replace(/\n|\r|\n\r/gm, "");
}
insertKeysArray.push("`" + dataKey + "`");
if (typeof value === "object") {
value = JSON.stringify(value);
}
insertValuesArray.push(value);
} }
/** ********************************************** */ /** ********************************************** */

View File

@ -24,7 +24,7 @@ const handler = require("../utils/handler");
* *
* @returns {Promise<object|null>} * @returns {Promise<object|null>}
*/ */
module.exports = async function deleteDb({ dbFullName, tableName, tableSchema, identifierColumnName, identifierValue, dbHost, dbPassword, dbUsername, encryptionKey, encryptionSalt }) { module.exports = async function deleteDb({ dbFullName, tableName, identifierColumnName, identifierValue, dbHost, dbPassword, dbUsername, encryptionKey, encryptionSalt }) {
try { try {
/** /**
* Check if data is valid * Check if data is valid
@ -50,7 +50,6 @@ module.exports = async function deleteDb({ dbFullName, tableName, tableSchema, i
dbUsername, dbUsername,
encryptionKey, encryptionKey,
encryptionSalt, encryptionSalt,
tableSchema,
}); });
//////////////////////////////////////// ////////////////////////////////////////