50 lines
2.0 KiB
JavaScript
50 lines
2.0 KiB
JavaScript
|
// @ts-check
|
||
|
|
||
|
const serverError = require("./serverError");
|
||
|
const fs = require("fs");
|
||
|
const path = require("path");
|
||
|
|
||
|
/** ****************************************************************************** */
|
||
|
/** ****************************************************************************** */
|
||
|
/** ****************************************************************************** */
|
||
|
/** ****************************************************************************** */
|
||
|
/** ****************************************************************************** */
|
||
|
/** ****************************************************************************** */
|
||
|
|
||
|
/**
|
||
|
* ==============================================================================
|
||
|
* @param {Object} params
|
||
|
* @param {string | number} params.userId
|
||
|
* @param {import("../../types").DSQL_DatabaseSchemaType[]} params.schemaData
|
||
|
* @returns {boolean}
|
||
|
*/
|
||
|
export default function setUserSchemaData({ userId, schemaData }) {
|
||
|
try {
|
||
|
const userSchemaFilePath = path.resolve(
|
||
|
process.cwd(),
|
||
|
`${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${userId}/main.json`
|
||
|
);
|
||
|
fs.writeFileSync(
|
||
|
userSchemaFilePath,
|
||
|
JSON.stringify(schemaData),
|
||
|
"utf8"
|
||
|
);
|
||
|
|
||
|
return true;
|
||
|
} catch (/** @type {any} */ error) {
|
||
|
serverError({
|
||
|
component: "/functions/backend/setUserSchemaData",
|
||
|
message: error.message,
|
||
|
});
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/** ****************************************************************************** */
|
||
|
/** ****************************************************************************** */
|
||
|
/** ****************************************************************************** */
|
||
|
/** ****************************************************************************** */
|
||
|
/** ****************************************************************************** */
|
||
|
/** ****************************************************************************** */
|