updates
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
/**
|
||||
* Imports: Handle imports
|
||||
*/
|
||||
|
||||
const encrypt = require("../../functions/encrypt");
|
||||
const handler = require("../utils/handler");
|
||||
const sanitizeHtml = require("sanitize-html");
|
||||
const sanitizeHtmlOptions = require("../utils/sanitizeHtmlOptions");
|
||||
|
||||
/**
|
||||
* add Function
|
||||
* ==============================================================================
|
||||
* @description Description
|
||||
*
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {string} params.dbFullName - Database full name
|
||||
* @param {string} params.tableName - Table name
|
||||
* @param {object} params.data - Data to add
|
||||
* @param {DSQL_TableSchemaType?} params.tableSchema - Table schema
|
||||
* @param {string?} params.duplicateColumnName - Duplicate column name
|
||||
* @param {string?} params.duplicateColumnValue - Duplicate column value
|
||||
* @param {boolean?} params.update - Update this row if it exists
|
||||
* @param {string?} params.dbHost - Database host
|
||||
* @param {string?} params.dbPassword - Database password
|
||||
* @param {string?} params.dbUsername - Database username
|
||||
* @param {string?} params.encryptionKey - Encryption key
|
||||
* @param {string?} params.encryptionSalt - Encryption salt
|
||||
*
|
||||
* @returns {object}
|
||||
*/
|
||||
module.exports = async function add({ dbFullName, tableName, data, tableSchema, duplicateColumnName, duplicateColumnValue, update, dbHost, dbPassword, dbUsername, encryptionKey, encryptionSalt }) {
|
||||
/**
|
||||
* Initialize variables
|
||||
*/
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Handle function logic
|
||||
*/
|
||||
if (duplicateColumnName && typeof duplicateColumnName === "string") {
|
||||
const duplicateValue = await handler({
|
||||
queryString: `SELECT * FROM \`${tableName}\` WHERE \`${duplicateColumnName}\`=?`,
|
||||
queryValuesArray: [duplicateColumnValue],
|
||||
database: dbFullName,
|
||||
dbHost,
|
||||
dbPassword,
|
||||
dbUsername,
|
||||
});
|
||||
|
||||
if (duplicateValue && duplicateValue[0] && !update) {
|
||||
return null;
|
||||
} else if (duplicateValue && duplicateValue[0] && update) {
|
||||
return await update();
|
||||
}
|
||||
} else if (duplicateColumnName && typeof duplicateColumnName === "object" && duplicateColumnValue && typeof duplicateColumnValue === "object") {
|
||||
const duplicateArray = duplicateColumnName.map((dupColName, index) => {
|
||||
return `\`${dupColName}\`='${duplicateColumnValue[index]}'`;
|
||||
});
|
||||
|
||||
const duplicateValue = await handler({
|
||||
queryString: `SELECT * FROM ${tableName} WHERE ${duplicateArray.join(" AND ")}`,
|
||||
database: dbFullName,
|
||||
});
|
||||
|
||||
if (duplicateValue && duplicateValue[0] && !update) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
const dataKeys = Object.keys(data);
|
||||
|
||||
let insertKeysArray = [];
|
||||
let insertValuesArray = [];
|
||||
|
||||
for (let i = 0; i < dataKeys.length; i++) {
|
||||
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;
|
||||
|
||||
if (!value) continue;
|
||||
|
||||
if (targetFieldSchema?.encrypted) {
|
||||
value = encrypt({ data: value, encryptionKey, encryptionSalt });
|
||||
}
|
||||
|
||||
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(dataValue);
|
||||
}
|
||||
|
||||
/** ********************************************** */
|
||||
|
||||
insertKeysArray.push("date_created");
|
||||
insertValuesArray.push(Date());
|
||||
|
||||
insertKeysArray.push("date_created_code");
|
||||
insertValuesArray.push(Date.now());
|
||||
|
||||
/** ********************************************** */
|
||||
|
||||
insertKeysArray.push("date_updated");
|
||||
insertValuesArray.push(Date());
|
||||
|
||||
insertKeysArray.push("date_updated_code");
|
||||
insertValuesArray.push(Date.now());
|
||||
|
||||
/** ********************************************** */
|
||||
|
||||
const query = `INSERT INTO \`${tableName}\` (${insertKeysArray.join(",")}) VALUES (${insertValuesArray.map(() => "?").join(",")})`;
|
||||
const queryValuesArray = insertValuesArray;
|
||||
|
||||
// const newInsert = await dbHandler(query, queryValuesArray);
|
||||
|
||||
// const query = `INSERT INTO ${tableName} (${insertKeysArray.join(",")}) VALUES (${insertValuesArray.join(",")})`;
|
||||
|
||||
const newInsert = await handler({
|
||||
queryString: query,
|
||||
database: dbFullName,
|
||||
queryValuesArray,
|
||||
dbHost,
|
||||
dbPassword,
|
||||
dbUsername,
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
tableSchema,
|
||||
});
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Return statement
|
||||
*/
|
||||
return newInsert;
|
||||
};
|
||||
@@ -0,0 +1,125 @@
|
||||
const fs = require("fs");
|
||||
const dbHandler = require("../dbHandler");
|
||||
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
/** ****************************************************************************** */
|
||||
|
||||
/**
|
||||
* Add Database Entry
|
||||
* ==============================================================================
|
||||
* @param {object} params - foundUser if any
|
||||
* @param {string} params.tableName - Table Name
|
||||
* @param {object} params.data - Data to be added
|
||||
* @param {string?} params.duplicateColumnName - Duplicate Column Name
|
||||
* @param {string | number?} params.duplicateColumnValue - Duplicate Column Value
|
||||
*/
|
||||
async function addDbEntry({ tableName, data, duplicateColumnName, duplicateColumnValue }) {
|
||||
/**
|
||||
* Check Duplicate if specified
|
||||
*
|
||||
* @description Check Duplicate if specified
|
||||
*/
|
||||
if (duplicateColumnName) {
|
||||
let duplicateEntry = await dbHandler(`SELECT ${duplicateColumnName} FROM ${tableName} WHERE ${duplicateColumnName}='${duplicateColumnValue}'`);
|
||||
|
||||
if (duplicateEntry && duplicateEntry[0]) return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
const dataKeys = Object.keys(data);
|
||||
|
||||
let insertKeysArray = [];
|
||||
let insertValuesArray = [];
|
||||
|
||||
for (let i = 0; i < dataKeys.length; i++) {
|
||||
const dataKey = dataKeys[i];
|
||||
let dataValue = data[dataKey];
|
||||
// const correspondingColumnObject = dbColumns.filter((col) => col.Field === dataKey);
|
||||
// const { Field, Type, Null, Key, Default, Extra } = correspondingColumnObject;
|
||||
|
||||
if (!dataValue) continue;
|
||||
|
||||
insertKeysArray.push("`" + dataKey + "`");
|
||||
|
||||
if (typeof dataValue === "object") {
|
||||
dataValue = JSON.stringify(data[dataKey]);
|
||||
}
|
||||
|
||||
// let parsedDataValue = dataValue.toString().replace(/\'/g, "\\'");
|
||||
|
||||
insertValuesArray.push(dataValue);
|
||||
}
|
||||
|
||||
/** ********************************************** */
|
||||
|
||||
let existingDateCreatedColumn = await dbHandler(`SHOW COLUMNS FROM \`${tableName}\` WHERE Field = 'date_created'`);
|
||||
if (!existingDateCreatedColumn || !existingDateCreatedColumn[0]) {
|
||||
await dbHandler(`ALTER TABLE ${tableName} ADD COLUMN date_created VARCHAR(255) NOT NULL`);
|
||||
}
|
||||
|
||||
insertKeysArray.push("date_created");
|
||||
insertValuesArray.push(Date());
|
||||
|
||||
/** ********************************************** */
|
||||
|
||||
let existingDateCreatedCodeColumn = await dbHandler(`SHOW COLUMNS FROM ${tableName} WHERE Field = 'date_created_code'`);
|
||||
if (!existingDateCreatedCodeColumn || !existingDateCreatedCodeColumn[0]) {
|
||||
await dbHandler(`ALTER TABLE ${tableName} ADD COLUMN date_created_code BIGINT NOT NULL`);
|
||||
}
|
||||
|
||||
insertKeysArray.push("date_created_code");
|
||||
insertValuesArray.push(Date.now());
|
||||
|
||||
/** ********************************************** */
|
||||
|
||||
let existingDateCodeColumn = await dbHandler(`SHOW COLUMNS FROM ${tableName} WHERE Field = 'date_code'`);
|
||||
if (existingDateCodeColumn && existingDateCodeColumn[0]) {
|
||||
insertKeysArray.push("date_code");
|
||||
insertValuesArray.push(Date.now());
|
||||
}
|
||||
|
||||
/** ********************************************** */
|
||||
/** ********************************************** */
|
||||
/** ********************************************** */
|
||||
|
||||
let existingDateUpdatedColumn = await dbHandler(`SHOW COLUMNS FROM ${tableName} WHERE Field = 'date_updated'`);
|
||||
if (!existingDateUpdatedColumn || !existingDateUpdatedColumn[0]) {
|
||||
await dbHandler(`ALTER TABLE ${tableName} ADD COLUMN date_updated VARCHAR(255) NOT NULL`);
|
||||
}
|
||||
|
||||
insertKeysArray.push("date_updated");
|
||||
insertValuesArray.push(Date());
|
||||
|
||||
/** ********************************************** */
|
||||
|
||||
let existingDateUpdatedCodeColumn = await dbHandler(`SHOW COLUMNS FROM ${tableName} WHERE Field = 'date_updated_code'`);
|
||||
if (!existingDateUpdatedCodeColumn || !existingDateUpdatedCodeColumn[0]) {
|
||||
await dbHandler(`ALTER TABLE ${tableName} ADD COLUMN date_updated_code BIGINT NOT NULL`);
|
||||
}
|
||||
|
||||
insertKeysArray.push("date_updated_code");
|
||||
insertValuesArray.push(Date.now());
|
||||
|
||||
/** ********************************************** */
|
||||
|
||||
const query = `INSERT INTO ${tableName} (${insertKeysArray.join(",")}) VALUES (${insertValuesArray.map((val) => "?").join(",")})`;
|
||||
const queryValuesArray = insertValuesArray;
|
||||
|
||||
const newInsert = await dbHandler(query, queryValuesArray);
|
||||
|
||||
/** ********************************************** */
|
||||
|
||||
return newInsert;
|
||||
|
||||
/** ********************************************** */
|
||||
/** ********************************************** */
|
||||
/** ********************************************** */
|
||||
}
|
||||
@@ -0,0 +1,139 @@
|
||||
/**
|
||||
* Imports: Handle imports
|
||||
*/
|
||||
|
||||
const handler = require("../utils/handler");
|
||||
|
||||
/**
|
||||
* Update DB Function
|
||||
* ==============================================================================
|
||||
* @description Description
|
||||
*
|
||||
* @param {object} params - An object containing the function parameters.
|
||||
* @param {string} params.dbFullName - Database full name
|
||||
* @param {string} params.tableName - Table name
|
||||
* @param {object} params.data - Data to add
|
||||
* @param {DSQL_TableSchemaType?} params.tableSchema - Table schema
|
||||
* @param {string} params.identifierColumnName - Update row identifier column name
|
||||
* @param {string|number} params.identifierValue - Update row identifier column value
|
||||
* @param {boolean?} params.update - Update this row if it exists
|
||||
* @param {string?} params.dbHost - Database host
|
||||
* @param {string?} params.dbPassword - Database password
|
||||
* @param {string?} params.dbUsername - Database username
|
||||
* @param {string?} params.encryptionKey - Encryption key
|
||||
* @param {string?} params.encryptionSalt - Encryption salt
|
||||
*
|
||||
* @returns {object}
|
||||
*/
|
||||
module.exports = async function update({ dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, update, dbHost, dbPassword, dbUsername, encryptionKey, encryptionSalt }) {
|
||||
/**
|
||||
* Initialize variables
|
||||
*/
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Handle function logic
|
||||
*/
|
||||
if (duplicateColumnName && typeof duplicateColumnName === "string") {
|
||||
const duplicateValue = await handler({
|
||||
queryString: `SELECT * FROM \`${tableName}\` WHERE \`${duplicateColumnName}\`=?`,
|
||||
queryValuesArray: [duplicateColumnValue],
|
||||
database: dbFullName,
|
||||
dbHost,
|
||||
dbPassword,
|
||||
dbUsername,
|
||||
});
|
||||
|
||||
if (duplicateValue && duplicateValue[0] && !update) {
|
||||
return null;
|
||||
} else if (duplicateValue && duplicateValue[0] && update) {
|
||||
return await update();
|
||||
}
|
||||
} else if (duplicateColumnName && typeof duplicateColumnName === "object" && duplicateColumnValue && typeof duplicateColumnValue === "object") {
|
||||
const duplicateArray = duplicateColumnName.map((dupColName, index) => {
|
||||
return `\`${dupColName}\`='${duplicateColumnValue[index]}'`;
|
||||
});
|
||||
|
||||
const duplicateValue = await handler({
|
||||
queryString: `SELECT * FROM ${tableName} WHERE ${duplicateArray.join(" AND ")}`,
|
||||
database: dbFullName,
|
||||
});
|
||||
|
||||
if (duplicateValue && duplicateValue[0] && !update) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
const dataKeys = Object.keys(data);
|
||||
|
||||
let insertKeysArray = [];
|
||||
let insertValuesArray = [];
|
||||
|
||||
for (let i = 0; i < dataKeys.length; i++) {
|
||||
const dataKey = dataKeys[i];
|
||||
// const correspondingColumnObject = dbColumns.filter((col) => col.Field === dataKey);
|
||||
// const { Field, Type, Null, Key, Default, Extra } = correspondingColumnObject;
|
||||
let value = data[dataKey];
|
||||
|
||||
const targetFieldSchemaArray = tableSchema ? tableSchema?.fields.filter((field) => field.fieldName === dataKey) : null;
|
||||
const targetFieldSchema = targetFieldSchemaArray && targetFieldSchemaArray[0] ? targetFieldSchemaArray[0] : null;
|
||||
|
||||
if (!value) continue;
|
||||
|
||||
if (targetFieldSchema?.encrypted) {
|
||||
value = await encrypt(value);
|
||||
}
|
||||
|
||||
if (targetFieldSchema?.richText) {
|
||||
value = sanitizeHtml(value, sanitizeHtmlOptions).replace(/\n|\r|\n\r/gm, "");
|
||||
}
|
||||
|
||||
insertKeysArray.push("`" + dataKey + "`");
|
||||
|
||||
let parsedDataValue = value.toString().replace(/(?<!\\)\'/g, "\\'");
|
||||
|
||||
insertValuesArray.push("'" + parsedDataValue + "'");
|
||||
}
|
||||
|
||||
/** ********************************************** */
|
||||
|
||||
insertKeysArray.push("date_created");
|
||||
insertValuesArray.push("'" + Date() + "'");
|
||||
|
||||
insertKeysArray.push("date_created_code");
|
||||
insertValuesArray.push("'" + Date.now() + "'");
|
||||
|
||||
/** ********************************************** */
|
||||
|
||||
insertKeysArray.push("date_updated");
|
||||
insertValuesArray.push("'" + Date() + "'");
|
||||
|
||||
insertKeysArray.push("date_updated_code");
|
||||
insertValuesArray.push("'" + Date.now() + "'");
|
||||
|
||||
/** ********************************************** */
|
||||
|
||||
const query = `INSERT INTO ${tableName} (${insertKeysArray.join(",")}) VALUES (${insertValuesArray.join(",")})`;
|
||||
|
||||
const newInsert = await handler({
|
||||
queryString: query,
|
||||
database: dbFullName,
|
||||
});
|
||||
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* Return statement
|
||||
*/
|
||||
return newInsert;
|
||||
};
|
||||
+2
-14
@@ -21,24 +21,12 @@ const logout = require("./auth/logout");
|
||||
* Media Functions Object
|
||||
* ==============================================================================
|
||||
*/
|
||||
const media = {
|
||||
imageInputToBase64: imageInputToBase64,
|
||||
const db = {
|
||||
add: imageInputToBase64,
|
||||
imageInputFileToBase64: imageInputFileToBase64,
|
||||
inputFileToBase64: inputFileToBase64,
|
||||
};
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Media Functions Object
|
||||
* ==============================================================================
|
||||
*/
|
||||
const auth = {
|
||||
google: {
|
||||
getAccessToken: getAccessToken,
|
||||
},
|
||||
logout: logout,
|
||||
};
|
||||
|
||||
/**
|
||||
* ==============================================================================
|
||||
* Main Export
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
/**
|
||||
* Regular expression to match default fields
|
||||
*
|
||||
* @description Regular expression to match default fields
|
||||
*/
|
||||
const defaultFieldsRegexp = /^id$|^date_created$|^date_created_code$|^date_created_timestamp$|^date_updated$|^date_updated_code$|^date_updated_timestamp$/;
|
||||
|
||||
/** ********************************************** */
|
||||
/** ********************************************** */
|
||||
/** ********************************************** */
|
||||
|
||||
module.exports = defaultFieldsRegexp;
|
||||
@@ -0,0 +1,92 @@
|
||||
const fs = require("fs");
|
||||
const parseDbResults = require("./parseDbResults");
|
||||
|
||||
/**
|
||||
* DB handler for specific database
|
||||
* ==============================================================================
|
||||
* @async
|
||||
* @param {object} params - Single object params
|
||||
* @param {string} params.queryString - SQL string
|
||||
* @param {string[]?} params.queryValuesArray - Values Array
|
||||
* @param {string} params.database - Database name
|
||||
* @param {DSQL_TableSchemaType?} params.tableSchema - Table schema
|
||||
* @param {string} params.dbHost - Database host
|
||||
* @param {string} params.dbUsername - Database username
|
||||
* @param {string} params.dbPassword - Database password
|
||||
* @param {string?} params.encryptionKey - Encryption key
|
||||
* @param {string?} params.encryptionSalt - Encryption salt
|
||||
*
|
||||
* @returns {Promise<object[]|null>}
|
||||
*/
|
||||
module.exports = async function handler({ queryString, queryValuesArray, database, tableSchema, dbHost, dbUsername, dbPassword, encryptionKey, encryptionSalt }) {
|
||||
const mysql = require("serverless-mysql")({
|
||||
config: {
|
||||
host: dbHost,
|
||||
user: dbUsername,
|
||||
password: dbPassword,
|
||||
database: database.toString().replace(/[^a-z0-9\_\-]/g, ""),
|
||||
charset: "utf8mb4",
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let results;
|
||||
|
||||
/**
|
||||
* Check if query values array is an array
|
||||
*/
|
||||
if (!queryString || !queryValuesArray || !Array.isArray(queryValuesArray) || !queryValuesArray[0]) {
|
||||
return null;
|
||||
}
|
||||
/**
|
||||
* Fetch from db
|
||||
*
|
||||
* @description Fetch data from db if no cache
|
||||
*/
|
||||
try {
|
||||
/**
|
||||
* Run Query
|
||||
*/
|
||||
results = await mysql.query(queryString, queryValuesArray);
|
||||
|
||||
/**
|
||||
* Clean up
|
||||
*/
|
||||
await mysql.end();
|
||||
} catch (error) {
|
||||
/**
|
||||
* Handle error and clean up
|
||||
*/
|
||||
console.log("\x1b[31mDSQL Database Handler ERROR\x1b[0m =>", database, error.message);
|
||||
|
||||
/**
|
||||
* Clean up
|
||||
*/
|
||||
await mysql.end();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return results
|
||||
*
|
||||
* @description Return results add to cache if "req" param is passed
|
||||
*/
|
||||
if (results && tableSchema) {
|
||||
try {
|
||||
const unparsedResults = JSON.parse(JSON.stringify(results));
|
||||
const parsedResults = await parseDbResults({ unparsedResults: unparsedResults, tableSchema: tableSchema, encryptionKey, encryptionSalt });
|
||||
return parsedResults;
|
||||
} catch (error) {
|
||||
console.log("\x1b[31mDSQL Database Handler ERROR\x1b[0m =>", database, error.message);
|
||||
return null;
|
||||
}
|
||||
} else if (results) {
|
||||
return JSON.parse(JSON.stringify(results));
|
||||
} else {
|
||||
console.log("\x1b[31mDSQL Database Handler No results returned\x1b[0m =>", results);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,70 @@
|
||||
const decrypt = require("../../functions/decrypt");
|
||||
const defaultFieldsRegexp = require("./defaultFieldsRegexp");
|
||||
|
||||
/**
|
||||
* Parse Database results
|
||||
* ==============================================================================
|
||||
* @description this function takes a database results array gotten from a DB handler
|
||||
* function, decrypts encrypted fields, and returns an updated array with no encrypted
|
||||
* fields
|
||||
*
|
||||
* @param {object} params - Single object params
|
||||
* @param {{}[]} params.unparsedResults - Array of data objects containing Fields(keys)
|
||||
* and corresponding values of the fields(values)
|
||||
* @param {DSQL_TableSchemaType} params.tableSchema - Table schema
|
||||
* @returns {Promise<object[]|null>}
|
||||
*/
|
||||
module.exports = async function parseDbResults({ unparsedResults, tableSchema, encryptionKey, encryptionSalt }) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let parsedResults = [];
|
||||
|
||||
try {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
for (let pr = 0; pr < unparsedResults.length; pr++) {
|
||||
let result = unparsedResults[pr];
|
||||
|
||||
let resultFieldNames = Object.keys(result);
|
||||
|
||||
for (let i = 0; i < resultFieldNames.length; i++) {
|
||||
const resultFieldName = resultFieldNames[i];
|
||||
let resultFieldSchema = tableSchema.fields[i];
|
||||
|
||||
if (resultFieldName?.match(defaultFieldsRegexp)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
let value = result[resultFieldName];
|
||||
|
||||
if (typeof value !== "number" && !value) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (resultFieldSchema?.encrypted) {
|
||||
if (value?.match(/./)) {
|
||||
result[resultFieldName] = decrypt({ encryptedString: value, encryptionKey, encryptionSalt });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
parsedResults.push(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
return parsedResults;
|
||||
} catch (error) {
|
||||
console.log("ERROR in parseDbResults Function =>", error.message);
|
||||
return unparsedResults;
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
const sanitizeHtmlOptions = {
|
||||
allowedTags: ["b", "i", "em", "strong", "a", "p", "span", "ul", "ol", "li", "h1", "h2", "h3", "h4", "h5", "h6", "img"],
|
||||
allowedAttributes: {
|
||||
a: ["href"],
|
||||
img: ["src", "alt", "width", "height", "class", "style"],
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = sanitizeHtmlOptions;
|
||||
Reference in New Issue
Block a user