Roll Back compile version
This commit is contained in:
+196
-179
@@ -1,188 +1,205 @@
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
import sanitizeHtmlOptions from "../html/sanitizeHtmlOptions";
|
||||
import updateDbEntry from "./updateDbEntry";
|
||||
import _ from "lodash";
|
||||
import encrypt from "../../dsql/encrypt";
|
||||
import connDbHandler from "../../../utils/db/conn-db-handler";
|
||||
import checkIfIsMaster from "../../../utils/check-if-is-master";
|
||||
import debugLog from "../../../utils/logging/debug-log";
|
||||
import purgeDefaultFields from "../../../utils/purge-default-fields";
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = addDbEntry;
|
||||
const sanitize_html_1 = __importDefault(require("sanitize-html"));
|
||||
const sanitizeHtmlOptions_1 = __importDefault(require("../html/sanitizeHtmlOptions"));
|
||||
const updateDbEntry_1 = __importDefault(require("./updateDbEntry"));
|
||||
const lodash_1 = __importDefault(require("lodash"));
|
||||
const encrypt_1 = __importDefault(require("../../dsql/encrypt"));
|
||||
const conn_db_handler_1 = __importDefault(require("../../../utils/db/conn-db-handler"));
|
||||
const check_if_is_master_1 = __importDefault(require("../../../utils/check-if-is-master"));
|
||||
const debug_log_1 = __importDefault(require("../../../utils/logging/debug-log"));
|
||||
const purge_default_fields_1 = __importDefault(require("../../../utils/purge-default-fields"));
|
||||
/**
|
||||
* Add a db Entry Function
|
||||
*/
|
||||
export default async function addDbEntry({ dbContext, paradigm, dbFullName, tableName, data, batchData, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, forceLocal, debug, }) {
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
: checkIfIsMaster({ dbContext, dbFullName });
|
||||
if (debug) {
|
||||
debugLog({
|
||||
log: isMaster,
|
||||
addTime: true,
|
||||
label: "isMaster",
|
||||
});
|
||||
}
|
||||
const DB_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_FULL_ACCESS_DB_CONN || global.DSQL_DB_CONN;
|
||||
const DB_RO_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
let newData = _.cloneDeep(data);
|
||||
if (newData) {
|
||||
newData = purgeDefaultFields(newData);
|
||||
}
|
||||
let newBatchData = _.cloneDeep(batchData);
|
||||
if (newBatchData) {
|
||||
newBatchData = purgeDefaultFields(newBatchData);
|
||||
}
|
||||
if (duplicateColumnName &&
|
||||
typeof duplicateColumnName === "string" &&
|
||||
newData) {
|
||||
const checkDuplicateQuery = `SELECT * FROM ${isMaster ? "" : `\`${dbFullName}\`.`}\`${tableName}\` WHERE \`${duplicateColumnName}\`=?`;
|
||||
const duplicateValue = await connDbHandler(DB_RO_CONN, checkDuplicateQuery, [duplicateColumnValue]);
|
||||
if ((duplicateValue === null || duplicateValue === void 0 ? void 0 : duplicateValue[0]) && !update) {
|
||||
function addDbEntry(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, paradigm, dbFullName, tableName, data, batchData, tableSchema, duplicateColumnName, duplicateColumnValue, update, encryptionKey, encryptionSalt, forceLocal, debug, }) {
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
: (0, check_if_is_master_1.default)({ dbContext, dbFullName });
|
||||
if (debug) {
|
||||
(0, debug_log_1.default)({
|
||||
log: isMaster,
|
||||
addTime: true,
|
||||
label: "isMaster",
|
||||
});
|
||||
}
|
||||
const DB_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_FULL_ACCESS_DB_CONN || global.DSQL_DB_CONN;
|
||||
const DB_RO_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_READ_ONLY_DB_CONN || global.DSQL_DB_CONN;
|
||||
let newData = lodash_1.default.cloneDeep(data);
|
||||
if (newData) {
|
||||
newData = (0, purge_default_fields_1.default)(newData);
|
||||
}
|
||||
let newBatchData = lodash_1.default.cloneDeep(batchData);
|
||||
if (newBatchData) {
|
||||
newBatchData = (0, purge_default_fields_1.default)(newBatchData);
|
||||
}
|
||||
if (duplicateColumnName &&
|
||||
typeof duplicateColumnName === "string" &&
|
||||
newData) {
|
||||
const checkDuplicateQuery = `SELECT * FROM ${isMaster ? "" : `\`${dbFullName}\`.`}\`${tableName}\` WHERE \`${duplicateColumnName}\`=?`;
|
||||
const duplicateValue = yield (0, conn_db_handler_1.default)(DB_RO_CONN, checkDuplicateQuery, [duplicateColumnValue]);
|
||||
if ((duplicateValue === null || duplicateValue === void 0 ? void 0 : duplicateValue[0]) && !update) {
|
||||
return {
|
||||
success: false,
|
||||
payload: undefined,
|
||||
msg: "Duplicate entry found",
|
||||
};
|
||||
}
|
||||
else if ((duplicateValue === null || duplicateValue === void 0 ? void 0 : duplicateValue[0]) && update) {
|
||||
return yield (0, updateDbEntry_1.default)({
|
||||
dbContext,
|
||||
dbFullName,
|
||||
tableName,
|
||||
data: newData,
|
||||
tableSchema,
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
identifierColumnName: duplicateColumnName,
|
||||
identifierValue: duplicateColumnValue || "",
|
||||
});
|
||||
}
|
||||
}
|
||||
function generateQuery(data) {
|
||||
var _a, _b, _c;
|
||||
const dataKeys = Object.keys(data);
|
||||
let insertKeysArray = [];
|
||||
let insertValuesArray = [];
|
||||
for (let i = 0; i < dataKeys.length; i++) {
|
||||
try {
|
||||
const dataKey = dataKeys[i];
|
||||
let value = data[dataKey];
|
||||
const targetFieldSchemaArray = tableSchema
|
||||
? (_a = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields) === null || _a === void 0 ? void 0 : _a.filter((field) => field.fieldName == dataKey)
|
||||
: null;
|
||||
const targetFieldSchema = targetFieldSchemaArray && targetFieldSchemaArray[0]
|
||||
? targetFieldSchemaArray[0]
|
||||
: null;
|
||||
if (value == null || value == undefined)
|
||||
continue;
|
||||
if (((_b = targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.dataType) === null || _b === void 0 ? void 0 : _b.match(/int$/i)) &&
|
||||
typeof value == "string" &&
|
||||
!(value === null || value === void 0 ? void 0 : value.match(/./)))
|
||||
continue;
|
||||
if (targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.encrypted) {
|
||||
value = (0, encrypt_1.default)({
|
||||
data: value,
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
});
|
||||
console.log("DSQL: Encrypted value =>", value);
|
||||
}
|
||||
const htmlRegex = /<[^>]+>/g;
|
||||
if ((targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.richText) ||
|
||||
String(value).match(htmlRegex)) {
|
||||
value = (0, sanitize_html_1.default)(value, sanitizeHtmlOptions_1.default);
|
||||
}
|
||||
if (targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.pattern) {
|
||||
const pattern = new RegExp(targetFieldSchema.pattern, targetFieldSchema.patternFlags || "");
|
||||
if (!pattern.test(value)) {
|
||||
console.log("DSQL: Pattern not matched =>", value);
|
||||
value = "";
|
||||
}
|
||||
}
|
||||
insertKeysArray.push("`" + dataKey + "`");
|
||||
if (typeof value === "object") {
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
if (typeof value == "number") {
|
||||
insertValuesArray.push(String(value));
|
||||
}
|
||||
else {
|
||||
insertValuesArray.push(value);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.log("DSQL: Error in parsing data keys =>", error.message);
|
||||
(_c = global.ERROR_CALLBACK) === null || _c === void 0 ? void 0 : _c.call(global, `Error parsing Data Keys`, error);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
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 queryValuesArray = insertValuesArray;
|
||||
return { queryValuesArray, insertValuesArray, insertKeysArray };
|
||||
}
|
||||
if (newData) {
|
||||
const { insertKeysArray, insertValuesArray, queryValuesArray } = generateQuery(newData);
|
||||
const query = `INSERT INTO ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` (${insertKeysArray.join(",")}) VALUES (${insertValuesArray.map(() => "?").join(",")})`;
|
||||
const newInsert = yield (0, conn_db_handler_1.default)(DB_CONN, query, queryValuesArray, debug);
|
||||
return {
|
||||
success: Boolean(newInsert === null || newInsert === void 0 ? void 0 : newInsert.insertId),
|
||||
payload: newInsert,
|
||||
queryObject: {
|
||||
sql: query,
|
||||
params: queryValuesArray,
|
||||
},
|
||||
};
|
||||
}
|
||||
else if (newBatchData) {
|
||||
let batchInsertKeysArray;
|
||||
let batchInsertValuesArray = [];
|
||||
let batchQueryValuesArray = [];
|
||||
for (let i = 0; i < newBatchData.length; i++) {
|
||||
const singleBatchData = newBatchData[i];
|
||||
const { insertKeysArray, insertValuesArray, queryValuesArray } = generateQuery(singleBatchData);
|
||||
if (!batchInsertKeysArray) {
|
||||
batchInsertKeysArray = insertKeysArray;
|
||||
}
|
||||
batchInsertValuesArray.push(insertValuesArray);
|
||||
batchQueryValuesArray.push(queryValuesArray);
|
||||
}
|
||||
const query = `INSERT INTO ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` (${batchInsertKeysArray === null || batchInsertKeysArray === void 0 ? void 0 : batchInsertKeysArray.join(",")}) VALUES ${batchInsertValuesArray
|
||||
.map((vl) => `(${vl.map(() => "?").join(",")})`)
|
||||
.join(",")}`;
|
||||
console.log("query", query);
|
||||
console.log("batchQueryValuesArray", batchQueryValuesArray);
|
||||
const newInsert = yield (0, conn_db_handler_1.default)(DB_CONN, query, batchQueryValuesArray.flat(), debug);
|
||||
if (debug) {
|
||||
(0, debug_log_1.default)({
|
||||
log: newInsert,
|
||||
addTime: true,
|
||||
label: "newInsert",
|
||||
});
|
||||
}
|
||||
return {
|
||||
success: Boolean(newInsert === null || newInsert === void 0 ? void 0 : newInsert.insertId),
|
||||
payload: newInsert,
|
||||
queryObject: {
|
||||
sql: query,
|
||||
params: batchQueryValuesArray.flat(),
|
||||
},
|
||||
};
|
||||
}
|
||||
else {
|
||||
return {
|
||||
success: false,
|
||||
payload: undefined,
|
||||
msg: "Duplicate entry found",
|
||||
msg: "No data provided",
|
||||
};
|
||||
}
|
||||
else if ((duplicateValue === null || duplicateValue === void 0 ? void 0 : duplicateValue[0]) && update) {
|
||||
return await updateDbEntry({
|
||||
dbContext,
|
||||
dbFullName,
|
||||
tableName,
|
||||
data: newData,
|
||||
tableSchema,
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
identifierColumnName: duplicateColumnName,
|
||||
identifierValue: duplicateColumnValue || "",
|
||||
});
|
||||
}
|
||||
}
|
||||
function generateQuery(data) {
|
||||
var _a, _b, _c;
|
||||
const dataKeys = Object.keys(data);
|
||||
let insertKeysArray = [];
|
||||
let insertValuesArray = [];
|
||||
for (let i = 0; i < dataKeys.length; i++) {
|
||||
try {
|
||||
const dataKey = dataKeys[i];
|
||||
let value = data[dataKey];
|
||||
const targetFieldSchemaArray = tableSchema
|
||||
? (_a = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields) === null || _a === void 0 ? void 0 : _a.filter((field) => field.fieldName == dataKey)
|
||||
: null;
|
||||
const targetFieldSchema = targetFieldSchemaArray && targetFieldSchemaArray[0]
|
||||
? targetFieldSchemaArray[0]
|
||||
: null;
|
||||
if (value == null || value == undefined)
|
||||
continue;
|
||||
if (((_b = targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.dataType) === null || _b === void 0 ? void 0 : _b.match(/int$/i)) &&
|
||||
typeof value == "string" &&
|
||||
!(value === null || value === void 0 ? void 0 : value.match(/./)))
|
||||
continue;
|
||||
if (targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.encrypted) {
|
||||
value = encrypt({
|
||||
data: value,
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
});
|
||||
console.log("DSQL: Encrypted value =>", value);
|
||||
}
|
||||
const htmlRegex = /<[^>]+>/g;
|
||||
if ((targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.richText) ||
|
||||
String(value).match(htmlRegex)) {
|
||||
value = sanitizeHtml(value, sanitizeHtmlOptions);
|
||||
}
|
||||
if (targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.pattern) {
|
||||
const pattern = new RegExp(targetFieldSchema.pattern, targetFieldSchema.patternFlags || "");
|
||||
if (!pattern.test(value)) {
|
||||
console.log("DSQL: Pattern not matched =>", value);
|
||||
value = "";
|
||||
}
|
||||
}
|
||||
insertKeysArray.push("`" + dataKey + "`");
|
||||
if (typeof value === "object") {
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
if (typeof value == "number") {
|
||||
insertValuesArray.push(String(value));
|
||||
}
|
||||
else {
|
||||
insertValuesArray.push(value);
|
||||
}
|
||||
}
|
||||
catch (error) {
|
||||
console.log("DSQL: Error in parsing data keys =>", error.message);
|
||||
(_c = global.ERROR_CALLBACK) === null || _c === void 0 ? void 0 : _c.call(global, `Error parsing Data Keys`, error);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
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 queryValuesArray = insertValuesArray;
|
||||
return { queryValuesArray, insertValuesArray, insertKeysArray };
|
||||
}
|
||||
if (newData) {
|
||||
const { insertKeysArray, insertValuesArray, queryValuesArray } = generateQuery(newData);
|
||||
const query = `INSERT INTO ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` (${insertKeysArray.join(",")}) VALUES (${insertValuesArray.map(() => "?").join(",")})`;
|
||||
const newInsert = await connDbHandler(DB_CONN, query, queryValuesArray, debug);
|
||||
return {
|
||||
success: Boolean(newInsert === null || newInsert === void 0 ? void 0 : newInsert.insertId),
|
||||
payload: newInsert,
|
||||
queryObject: {
|
||||
sql: query,
|
||||
params: queryValuesArray,
|
||||
},
|
||||
};
|
||||
}
|
||||
else if (newBatchData) {
|
||||
let batchInsertKeysArray;
|
||||
let batchInsertValuesArray = [];
|
||||
let batchQueryValuesArray = [];
|
||||
for (let i = 0; i < newBatchData.length; i++) {
|
||||
const singleBatchData = newBatchData[i];
|
||||
const { insertKeysArray, insertValuesArray, queryValuesArray } = generateQuery(singleBatchData);
|
||||
if (!batchInsertKeysArray) {
|
||||
batchInsertKeysArray = insertKeysArray;
|
||||
}
|
||||
batchInsertValuesArray.push(insertValuesArray);
|
||||
batchQueryValuesArray.push(queryValuesArray);
|
||||
}
|
||||
const query = `INSERT INTO ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` (${batchInsertKeysArray === null || batchInsertKeysArray === void 0 ? void 0 : batchInsertKeysArray.join(",")}) VALUES ${batchInsertValuesArray
|
||||
.map((vl) => `(${vl.map(() => "?").join(",")})`)
|
||||
.join(",")}`;
|
||||
console.log("query", query);
|
||||
console.log("batchQueryValuesArray", batchQueryValuesArray);
|
||||
const newInsert = await connDbHandler(DB_CONN, query, batchQueryValuesArray.flat(), debug);
|
||||
if (debug) {
|
||||
debugLog({
|
||||
log: newInsert,
|
||||
addTime: true,
|
||||
label: "newInsert",
|
||||
});
|
||||
}
|
||||
return {
|
||||
success: Boolean(newInsert === null || newInsert === void 0 ? void 0 : newInsert.insertId),
|
||||
payload: newInsert,
|
||||
queryObject: {
|
||||
sql: query,
|
||||
params: batchQueryValuesArray.flat(),
|
||||
},
|
||||
};
|
||||
}
|
||||
else {
|
||||
return {
|
||||
success: false,
|
||||
payload: undefined,
|
||||
msg: "No data provided",
|
||||
};
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+46
-29
@@ -1,34 +1,51 @@
|
||||
import checkIfIsMaster from "../../../utils/check-if-is-master";
|
||||
import connDbHandler from "../../../utils/db/conn-db-handler";
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = deleteDbEntry;
|
||||
const check_if_is_master_1 = __importDefault(require("../../../utils/check-if-is-master"));
|
||||
const conn_db_handler_1 = __importDefault(require("../../../utils/db/conn-db-handler"));
|
||||
/**
|
||||
* # Delete DB Entry Function
|
||||
* @description
|
||||
*/
|
||||
export default async function deleteDbEntry({ dbContext, dbFullName, tableName, identifierColumnName, identifierValue, forceLocal, }) {
|
||||
var _a;
|
||||
try {
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
: checkIfIsMaster({ dbContext, dbFullName });
|
||||
const DB_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_FULL_ACCESS_DB_CONN || global.DSQL_DB_CONN;
|
||||
/**
|
||||
* Execution
|
||||
*
|
||||
* @description
|
||||
*/
|
||||
const query = `DELETE FROM ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` WHERE \`${identifierColumnName.toString()}\`=?`;
|
||||
const deletedEntry = await connDbHandler(DB_CONN, query, [
|
||||
identifierValue,
|
||||
]);
|
||||
/**
|
||||
* Return statement
|
||||
*/
|
||||
return deletedEntry;
|
||||
}
|
||||
catch (error) {
|
||||
(_a = global.ERROR_CALLBACK) === null || _a === void 0 ? void 0 : _a.call(global, `Error Deleting Entry`, error);
|
||||
return null;
|
||||
}
|
||||
function deleteDbEntry(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, dbFullName, tableName, identifierColumnName, identifierValue, forceLocal, }) {
|
||||
var _b;
|
||||
try {
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
: (0, check_if_is_master_1.default)({ dbContext, dbFullName });
|
||||
const DB_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_FULL_ACCESS_DB_CONN || global.DSQL_DB_CONN;
|
||||
/**
|
||||
* Execution
|
||||
*
|
||||
* @description
|
||||
*/
|
||||
const query = `DELETE FROM ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` WHERE \`${identifierColumnName.toString()}\`=?`;
|
||||
const deletedEntry = yield (0, conn_db_handler_1.default)(DB_CONN, query, [
|
||||
identifierValue,
|
||||
]);
|
||||
/**
|
||||
* Return statement
|
||||
*/
|
||||
return deletedEntry;
|
||||
}
|
||||
catch (error) {
|
||||
(_b = global.ERROR_CALLBACK) === null || _b === void 0 ? void 0 : _b.call(global, `Error Deleting Entry`, error);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = pathTraversalCheck;
|
||||
/**
|
||||
* # Path Traversal Check
|
||||
* @returns {string}
|
||||
*/
|
||||
export default function pathTraversalCheck(text) {
|
||||
function pathTraversalCheck(text) {
|
||||
return text.toString().replace(/\//g, "");
|
||||
}
|
||||
|
||||
+146
-128
@@ -1,137 +1,155 @@
|
||||
import fullAccessDbHandler from "../fullAccessDbHandler";
|
||||
import varReadOnlyDatabaseDbHandler from "../varReadOnlyDatabaseDbHandler";
|
||||
import serverError from "../serverError";
|
||||
import addDbEntry from "./addDbEntry";
|
||||
import updateDbEntry from "./updateDbEntry";
|
||||
import deleteDbEntry from "./deleteDbEntry";
|
||||
import trimSql from "../../../utils/trim-sql";
|
||||
export const DbContextsArray = ["Master", "Dsql User"];
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.DbContextsArray = void 0;
|
||||
exports.default = runQuery;
|
||||
const fullAccessDbHandler_1 = __importDefault(require("../fullAccessDbHandler"));
|
||||
const varReadOnlyDatabaseDbHandler_1 = __importDefault(require("../varReadOnlyDatabaseDbHandler"));
|
||||
const serverError_1 = __importDefault(require("../serverError"));
|
||||
const addDbEntry_1 = __importDefault(require("./addDbEntry"));
|
||||
const updateDbEntry_1 = __importDefault(require("./updateDbEntry"));
|
||||
const deleteDbEntry_1 = __importDefault(require("./deleteDbEntry"));
|
||||
const trim_sql_1 = __importDefault(require("../../../utils/trim-sql"));
|
||||
exports.DbContextsArray = ["Master", "Dsql User"];
|
||||
/**
|
||||
* # Run DSQL users queries
|
||||
*/
|
||||
export default async function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName, debug, dbContext, forceLocal, }) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let result;
|
||||
let error;
|
||||
let tableSchema;
|
||||
if (dbSchema) {
|
||||
function runQuery(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbFullName, query, readOnly, dbSchema, queryValuesArray, tableName, debug, dbContext, forceLocal, }) {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
let result;
|
||||
let error;
|
||||
let tableSchema;
|
||||
if (dbSchema) {
|
||||
try {
|
||||
const table = tableName
|
||||
? tableName
|
||||
: typeof query == "string"
|
||||
? null
|
||||
: query
|
||||
? query === null || query === void 0 ? void 0 : query.table
|
||||
: null;
|
||||
if (!table)
|
||||
throw new Error("No table name provided");
|
||||
tableSchema = dbSchema.tables.filter((tb) => (tb === null || tb === void 0 ? void 0 : tb.tableName) === table)[0];
|
||||
}
|
||||
catch (_err) {
|
||||
// console.log("ERROR getting tableSchema: ", _err.message);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
try {
|
||||
const table = tableName
|
||||
? tableName
|
||||
: typeof query == "string"
|
||||
? null
|
||||
: query
|
||||
? query === null || query === void 0 ? void 0 : query.table
|
||||
: null;
|
||||
if (!table)
|
||||
throw new Error("No table name provided");
|
||||
tableSchema = dbSchema.tables.filter((tb) => (tb === null || tb === void 0 ? void 0 : tb.tableName) === table)[0];
|
||||
if (typeof query === "string") {
|
||||
const formattedQuery = (0, trim_sql_1.default)(query);
|
||||
if (debug && global.DSQL_USE_LOCAL) {
|
||||
console.log("runQuery:formattedQuery", formattedQuery);
|
||||
}
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/
|
||||
if (readOnly && formattedQuery.match(/^alter|^delete|^create/i)) {
|
||||
throw new Error("Wrong Input!");
|
||||
}
|
||||
if (readOnly) {
|
||||
result = yield (0, varReadOnlyDatabaseDbHandler_1.default)({
|
||||
queryString: formattedQuery,
|
||||
queryValuesArray: queryValuesArray === null || queryValuesArray === void 0 ? void 0 : queryValuesArray.map((vl) => String(vl)),
|
||||
tableSchema,
|
||||
forceLocal,
|
||||
});
|
||||
}
|
||||
else {
|
||||
result = yield (0, fullAccessDbHandler_1.default)({
|
||||
queryString: formattedQuery,
|
||||
queryValuesArray: queryValuesArray === null || queryValuesArray === void 0 ? void 0 : queryValuesArray.map((vl) => String(vl)),
|
||||
tableSchema,
|
||||
forceLocal,
|
||||
});
|
||||
}
|
||||
}
|
||||
else if (typeof query === "object") {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
const { data, action, table, identifierColumnName, identifierValue, update, duplicateColumnName, duplicateColumnValue, } = query;
|
||||
switch (action.toLowerCase()) {
|
||||
case "insert":
|
||||
result = yield (0, addDbEntry_1.default)({
|
||||
dbContext,
|
||||
dbFullName,
|
||||
tableName: table,
|
||||
data: data,
|
||||
update,
|
||||
duplicateColumnName,
|
||||
duplicateColumnValue,
|
||||
tableSchema,
|
||||
debug,
|
||||
});
|
||||
if (!(result === null || result === void 0 ? void 0 : result.insertId)) {
|
||||
error = "Couldn't insert data";
|
||||
}
|
||||
break;
|
||||
case "update":
|
||||
result = yield (0, updateDbEntry_1.default)({
|
||||
dbContext,
|
||||
dbFullName,
|
||||
tableName: table,
|
||||
data: data,
|
||||
identifierColumnName,
|
||||
identifierValue,
|
||||
tableSchema,
|
||||
});
|
||||
break;
|
||||
case "delete":
|
||||
result = yield (0, deleteDbEntry_1.default)({
|
||||
dbContext,
|
||||
dbFullName,
|
||||
tableName: table,
|
||||
identifierColumnName,
|
||||
identifierValue,
|
||||
tableSchema,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
result = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (_err) {
|
||||
// console.log("ERROR getting tableSchema: ", _err.message);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
try {
|
||||
if (typeof query === "string") {
|
||||
const formattedQuery = trimSql(query);
|
||||
catch (err) {
|
||||
(0, serverError_1.default)({
|
||||
component: "functions/backend/runQuery",
|
||||
message: err.message,
|
||||
});
|
||||
if (debug && global.DSQL_USE_LOCAL) {
|
||||
console.log("runQuery:formattedQuery", formattedQuery);
|
||||
}
|
||||
/**
|
||||
* Input Validation
|
||||
*
|
||||
* @description Input Validation
|
||||
*/
|
||||
if (readOnly && formattedQuery.match(/^alter|^delete|^create/i)) {
|
||||
throw new Error("Wrong Input!");
|
||||
}
|
||||
if (readOnly) {
|
||||
result = await varReadOnlyDatabaseDbHandler({
|
||||
queryString: formattedQuery,
|
||||
queryValuesArray: queryValuesArray === null || queryValuesArray === void 0 ? void 0 : queryValuesArray.map((vl) => String(vl)),
|
||||
tableSchema,
|
||||
forceLocal,
|
||||
});
|
||||
}
|
||||
else {
|
||||
result = await fullAccessDbHandler({
|
||||
queryString: formattedQuery,
|
||||
queryValuesArray: queryValuesArray === null || queryValuesArray === void 0 ? void 0 : queryValuesArray.map((vl) => String(vl)),
|
||||
tableSchema,
|
||||
forceLocal,
|
||||
});
|
||||
console.log("runQuery:error", err.message);
|
||||
}
|
||||
result = null;
|
||||
error = err.message;
|
||||
}
|
||||
else if (typeof query === "object") {
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
const { data, action, table, identifierColumnName, identifierValue, update, duplicateColumnName, duplicateColumnValue, } = query;
|
||||
switch (action.toLowerCase()) {
|
||||
case "insert":
|
||||
result = await addDbEntry({
|
||||
dbContext,
|
||||
dbFullName,
|
||||
tableName: table,
|
||||
data: data,
|
||||
update,
|
||||
duplicateColumnName,
|
||||
duplicateColumnValue,
|
||||
tableSchema,
|
||||
debug,
|
||||
});
|
||||
if (!(result === null || result === void 0 ? void 0 : result.insertId)) {
|
||||
error = "Couldn't insert data";
|
||||
}
|
||||
break;
|
||||
case "update":
|
||||
result = await updateDbEntry({
|
||||
dbContext,
|
||||
dbFullName,
|
||||
tableName: table,
|
||||
data: data,
|
||||
identifierColumnName,
|
||||
identifierValue,
|
||||
tableSchema,
|
||||
});
|
||||
break;
|
||||
case "delete":
|
||||
result = await deleteDbEntry({
|
||||
dbContext,
|
||||
dbFullName,
|
||||
tableName: table,
|
||||
identifierColumnName,
|
||||
identifierValue,
|
||||
tableSchema,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
result = null;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
serverError({
|
||||
component: "functions/backend/runQuery",
|
||||
message: err.message,
|
||||
});
|
||||
if (debug && global.DSQL_USE_LOCAL) {
|
||||
console.log("runQuery:error", err.message);
|
||||
}
|
||||
result = null;
|
||||
error = err.message;
|
||||
}
|
||||
return { result, error };
|
||||
return { result, error };
|
||||
});
|
||||
}
|
||||
|
||||
+8
-3
@@ -1,4 +1,9 @@
|
||||
import _ from "lodash";
|
||||
"use strict";
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const lodash_1 = __importDefault(require("lodash"));
|
||||
/**
|
||||
* Sanitize SQL function
|
||||
* ==============================================================================
|
||||
@@ -84,7 +89,7 @@ function sanitizeObjects(object, spaces) {
|
||||
* @returns {string[]|number[]|object[]}
|
||||
*/
|
||||
function sanitizeArrays(array, spaces) {
|
||||
let arrayUpdated = _.cloneDeep(array);
|
||||
let arrayUpdated = lodash_1.default.cloneDeep(array);
|
||||
arrayUpdated.forEach((item, index) => {
|
||||
const value = item;
|
||||
if (!value) {
|
||||
@@ -103,4 +108,4 @@ function sanitizeArrays(array, spaces) {
|
||||
});
|
||||
return arrayUpdated;
|
||||
}
|
||||
export default sanitizeSql;
|
||||
exports.default = sanitizeSql;
|
||||
|
||||
+135
-118
@@ -1,127 +1,144 @@
|
||||
import sanitizeHtml from "sanitize-html";
|
||||
import sanitizeHtmlOptions from "../html/sanitizeHtmlOptions";
|
||||
import encrypt from "../../dsql/encrypt";
|
||||
import checkIfIsMaster from "../../../utils/check-if-is-master";
|
||||
import connDbHandler from "../../../utils/db/conn-db-handler";
|
||||
import _ from "lodash";
|
||||
import purgeDefaultFields from "../../../utils/purge-default-fields";
|
||||
"use strict";
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = updateDbEntry;
|
||||
const sanitize_html_1 = __importDefault(require("sanitize-html"));
|
||||
const sanitizeHtmlOptions_1 = __importDefault(require("../html/sanitizeHtmlOptions"));
|
||||
const encrypt_1 = __importDefault(require("../../dsql/encrypt"));
|
||||
const check_if_is_master_1 = __importDefault(require("../../../utils/check-if-is-master"));
|
||||
const conn_db_handler_1 = __importDefault(require("../../../utils/db/conn-db-handler"));
|
||||
const lodash_1 = __importDefault(require("lodash"));
|
||||
const purge_default_fields_1 = __importDefault(require("../../../utils/purge-default-fields"));
|
||||
/**
|
||||
* # Update DB Function
|
||||
* @description
|
||||
*/
|
||||
export default async function updateDbEntry({ dbContext, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, forceLocal, }) {
|
||||
var _a;
|
||||
/**
|
||||
* Check if data is valid
|
||||
*/
|
||||
if (!data || !Object.keys(data).length) {
|
||||
return {
|
||||
success: false,
|
||||
payload: undefined,
|
||||
msg: "No data provided",
|
||||
};
|
||||
}
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
: checkIfIsMaster({ dbContext, dbFullName });
|
||||
const DB_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_FULL_ACCESS_DB_CONN || global.DSQL_DB_CONN;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
let newData = _.cloneDeep(data);
|
||||
newData = purgeDefaultFields(newData);
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
const dataKeys = Object.keys(newData);
|
||||
let updateKeyValueArray = [];
|
||||
let updateValues = [];
|
||||
for (let i = 0; i < dataKeys.length; i++) {
|
||||
try {
|
||||
const dataKey = dataKeys[i];
|
||||
let value = newData[dataKey];
|
||||
const targetFieldSchemaArray = tableSchema
|
||||
? (_a = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields) === null || _a === void 0 ? void 0 : _a.filter((field) => field.fieldName === dataKey)
|
||||
: null;
|
||||
const targetFieldSchema = targetFieldSchemaArray && targetFieldSchemaArray[0]
|
||||
? targetFieldSchemaArray[0]
|
||||
: null;
|
||||
if (value == null || value == undefined)
|
||||
continue;
|
||||
const htmlRegex = /<[^>]+>/g;
|
||||
if ((targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.richText) || String(value).match(htmlRegex)) {
|
||||
value = sanitizeHtml(value, sanitizeHtmlOptions);
|
||||
}
|
||||
if (targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.encrypted) {
|
||||
value = encrypt({
|
||||
data: value,
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
});
|
||||
}
|
||||
if (typeof value === "object") {
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
if (targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.pattern) {
|
||||
const pattern = new RegExp(targetFieldSchema.pattern, targetFieldSchema.patternFlags || "");
|
||||
if (!pattern.test(value)) {
|
||||
console.log("DSQL: Pattern not matched =>", value);
|
||||
value = "";
|
||||
function updateDbEntry(_a) {
|
||||
return __awaiter(this, arguments, void 0, function* ({ dbContext, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt, forceLocal, }) {
|
||||
var _b;
|
||||
/**
|
||||
* Check if data is valid
|
||||
*/
|
||||
if (!data || !Object.keys(data).length) {
|
||||
return {
|
||||
success: false,
|
||||
payload: undefined,
|
||||
msg: "No data provided",
|
||||
};
|
||||
}
|
||||
const isMaster = forceLocal
|
||||
? true
|
||||
: (0, check_if_is_master_1.default)({ dbContext, dbFullName });
|
||||
const DB_CONN = isMaster
|
||||
? global.DSQL_DB_CONN
|
||||
: global.DSQL_FULL_ACCESS_DB_CONN || global.DSQL_DB_CONN;
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
let newData = lodash_1.default.cloneDeep(data);
|
||||
newData = (0, purge_default_fields_1.default)(newData);
|
||||
/**
|
||||
* Declare variables
|
||||
*
|
||||
* @description Declare "results" variable
|
||||
*/
|
||||
const dataKeys = Object.keys(newData);
|
||||
let updateKeyValueArray = [];
|
||||
let updateValues = [];
|
||||
for (let i = 0; i < dataKeys.length; i++) {
|
||||
try {
|
||||
const dataKey = dataKeys[i];
|
||||
let value = newData[dataKey];
|
||||
const targetFieldSchemaArray = tableSchema
|
||||
? (_b = tableSchema === null || tableSchema === void 0 ? void 0 : tableSchema.fields) === null || _b === void 0 ? void 0 : _b.filter((field) => field.fieldName === dataKey)
|
||||
: null;
|
||||
const targetFieldSchema = targetFieldSchemaArray && targetFieldSchemaArray[0]
|
||||
? targetFieldSchemaArray[0]
|
||||
: null;
|
||||
if (value == null || value == undefined)
|
||||
continue;
|
||||
const htmlRegex = /<[^>]+>/g;
|
||||
if ((targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.richText) || String(value).match(htmlRegex)) {
|
||||
value = (0, sanitize_html_1.default)(value, sanitizeHtmlOptions_1.default);
|
||||
}
|
||||
if (targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.encrypted) {
|
||||
value = (0, encrypt_1.default)({
|
||||
data: value,
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
});
|
||||
}
|
||||
if (typeof value === "object") {
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
if (targetFieldSchema === null || targetFieldSchema === void 0 ? void 0 : targetFieldSchema.pattern) {
|
||||
const pattern = new RegExp(targetFieldSchema.pattern, targetFieldSchema.patternFlags || "");
|
||||
if (!pattern.test(value)) {
|
||||
console.log("DSQL: Pattern not matched =>", value);
|
||||
value = "";
|
||||
}
|
||||
}
|
||||
if (typeof value === "string" && value.match(/^null$/i)) {
|
||||
value = {
|
||||
toSqlString: function () {
|
||||
return "NULL";
|
||||
},
|
||||
};
|
||||
}
|
||||
if (typeof value === "string" && !value.match(/./i)) {
|
||||
value = {
|
||||
toSqlString: function () {
|
||||
return "NULL";
|
||||
},
|
||||
};
|
||||
}
|
||||
updateKeyValueArray.push(`\`${dataKey}\`=?`);
|
||||
if (typeof value == "number") {
|
||||
updateValues.push(String(value));
|
||||
}
|
||||
else {
|
||||
updateValues.push(value);
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
if (typeof value === "string" && value.match(/^null$/i)) {
|
||||
value = {
|
||||
toSqlString: function () {
|
||||
return "NULL";
|
||||
},
|
||||
};
|
||||
catch ( /** @type {any} */error) {
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
console.log("DSQL: Error in parsing data keys in update function =>", error.message);
|
||||
continue;
|
||||
}
|
||||
if (typeof value === "string" && !value.match(/./i)) {
|
||||
value = {
|
||||
toSqlString: function () {
|
||||
return "NULL";
|
||||
},
|
||||
};
|
||||
}
|
||||
updateKeyValueArray.push(`\`${dataKey}\`=?`);
|
||||
if (typeof value == "number") {
|
||||
updateValues.push(String(value));
|
||||
}
|
||||
else {
|
||||
updateValues.push(value);
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
}
|
||||
catch ( /** @type {any} */error) {
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
console.log("DSQL: Error in parsing data keys in update function =>", error.message);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
updateKeyValueArray.push(`date_updated='${Date()}'`);
|
||||
updateKeyValueArray.push(`date_updated_code='${Date.now()}'`);
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const query = `UPDATE ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` SET ${updateKeyValueArray.join(",")} WHERE \`${identifierColumnName}\`=?`;
|
||||
updateValues.push(identifierValue);
|
||||
const updatedEntry = await connDbHandler(DB_CONN, query, updateValues);
|
||||
/**
|
||||
* Return statement
|
||||
*/
|
||||
return {
|
||||
success: Boolean(updatedEntry === null || updatedEntry === void 0 ? void 0 : updatedEntry.affectedRows),
|
||||
payload: updatedEntry,
|
||||
queryObject: {
|
||||
sql: query,
|
||||
params: updateValues,
|
||||
},
|
||||
};
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
updateKeyValueArray.push(`date_updated='${Date()}'`);
|
||||
updateKeyValueArray.push(`date_updated_code='${Date.now()}'`);
|
||||
////////////////////////////////////////
|
||||
////////////////////////////////////////
|
||||
const query = `UPDATE ${isMaster && !dbFullName ? "" : `\`${dbFullName}\`.`}\`${tableName}\` SET ${updateKeyValueArray.join(",")} WHERE \`${identifierColumnName}\`=?`;
|
||||
updateValues.push(identifierValue);
|
||||
const updatedEntry = yield (0, conn_db_handler_1.default)(DB_CONN, query, updateValues);
|
||||
/**
|
||||
* Return statement
|
||||
*/
|
||||
return {
|
||||
success: Boolean(updatedEntry === null || updatedEntry === void 0 ? void 0 : updatedEntry.affectedRows),
|
||||
payload: updatedEntry,
|
||||
queryObject: {
|
||||
sql: query,
|
||||
params: updateValues,
|
||||
},
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user