77 lines
4.2 KiB
JavaScript
77 lines
4.2 KiB
JavaScript
"use strict";
|
|
exports.id = 2630;
|
|
exports.ids = [2630];
|
|
exports.modules = {
|
|
|
|
/***/ 2630:
|
|
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
|
|
|
|
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
|
|
/* harmony export */ "Z": () => (/* binding */ importExportTableDataFn)
|
|
/* harmony export */ });
|
|
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(5338);
|
|
/* harmony import */ var _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_0__);
|
|
// @ts-check
|
|
|
|
const serverError = __webpack_require__(2163);
|
|
const DB_HANDLER = __webpack_require__(2224);
|
|
/** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /**
|
|
* @typedef {object} ExportTableDataFnReturn
|
|
* @property {any} [tableData]
|
|
*/ /**
|
|
* ==============================================================================
|
|
* @param {Object} params - Single object parameter
|
|
* @param {"export" | "import"} params.paradigm
|
|
* @param {string | number} params.userId
|
|
* @param {string} params.dbName
|
|
* @param {string} params.tableName
|
|
* @param {any} params.payload
|
|
* @param {"JSON" | "base64" | "object"} params.payloadType
|
|
* @return {Promise<ExportTableDataFnReturn | null>}
|
|
*/ async function importExportTableDataFn({ paradigm , userId , dbName , tableName , payload , payloadType , }) {
|
|
/** @type {ExportTableDataFnReturn} */ let returnObject = {};
|
|
try {
|
|
const dbFullName = `${process.env.DSQL_USER_DB_PREFIX}${userId}_${dbName.replace(/ /g, "")}`;
|
|
switch(paradigm){
|
|
case "export":
|
|
const tableData = await DB_HANDLER(`SELECT * FROM \`${dbFullName}\`.\`${tableName}\``);
|
|
returnObject["tableData"] = tableData;
|
|
break;
|
|
case "import":
|
|
const jsonData = payloadType == "base64" ? Buffer.from(payload, "base64").toString() : payloadType == "JSON" ? payload : payload;
|
|
const writeData = payloadType === "object" ? payload : JSON.parse(jsonData);
|
|
for(let i = 0; i < writeData.length; i++){
|
|
const dataToWrite = writeData[i];
|
|
const newEntry = await _package_shared_functions_backend_db_addDbEntry__WEBPACK_IMPORTED_MODULE_0___default()({
|
|
data: dataToWrite,
|
|
dbFullName: dbFullName,
|
|
tableName: tableName,
|
|
dbContext: "Dsql User",
|
|
paradigm: "Full Access",
|
|
duplicateColumnName: "id",
|
|
duplicateColumnValue: dataToWrite?.id,
|
|
update: true
|
|
});
|
|
if (newEntry.error) {
|
|
throw new Error(newEntry.error);
|
|
}
|
|
}
|
|
break;
|
|
default:
|
|
return null;
|
|
}
|
|
return returnObject;
|
|
} catch (/** @type {any} */ error) {
|
|
serverError({
|
|
component: "/functions/backend/importExportTableDataFn",
|
|
message: error.message
|
|
});
|
|
return null;
|
|
}
|
|
} /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */ /** ****************************************************************************** */
|
|
|
|
|
|
/***/ })
|
|
|
|
};
|
|
; |