diff --git a/engine/db/add.js b/engine/db/add.js index b3ed5f2..d87d8ef 100644 --- a/engine/db/add.js +++ b/engine/db/add.js @@ -95,29 +95,33 @@ module.exports = async function add({ dbFullName, tableName, data, tableSchema, let insertValuesArray = []; for (let i = 0; i < dataKeys.length; i++) { - const dataKey = dataKeys[i]; - let value = data[dataKey]; + try { + const dataKey = dataKeys[i]; + let value = data[dataKey]; - const targetFieldSchemaArray = tableSchema ? tableSchema?.fields.filter((field) => field.fieldName === dataKey) : null; - const targetFieldSchema = targetFieldSchemaArray && targetFieldSchemaArray[0] ? targetFieldSchemaArray[0] : null; + const targetFieldSchemaArray = tableSchema ? tableSchema?.fields.filter((field) => field.fieldName === dataKey) : null; + const targetFieldSchema = targetFieldSchemaArray && targetFieldSchemaArray[0] ? targetFieldSchemaArray[0] : null; - if (!value) continue; + if (!value) continue; - if (targetFieldSchema?.encrypted) { - value = encrypt({ data: value, encryptionKey, encryptionSalt }); + if (targetFieldSchema?.encrypted) { + 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); } /** ********************************************** */ diff --git a/engine/db/deleteDb.js b/engine/db/deleteDb.js index b454785..7c7cf14 100644 --- a/engine/db/deleteDb.js +++ b/engine/db/deleteDb.js @@ -24,7 +24,7 @@ const handler = require("../utils/handler"); * * @returns {Promise} */ -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 { /** * Check if data is valid @@ -50,7 +50,6 @@ module.exports = async function deleteDb({ dbFullName, tableName, tableSchema, i dbUsername, encryptionKey, encryptionSalt, - tableSchema, }); ////////////////////////////////////////