datasquirel/package-shared/functions/backend/setUserSchemaData.ts
2025-01-10 20:10:28 +01:00

46 lines
1.4 KiB
TypeScript
Executable File

import serverError from "./serverError";
import fs from "fs";
import path from "path";
import { DSQL_DatabaseSchemaType } from "../../types";
type Param = {
userId: string | number;
schemaData: DSQL_DatabaseSchemaType[];
};
/**
* # Set User Schema Data
*/
export default function setUserSchemaData({
userId,
schemaData,
}: Param): boolean {
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 (error: any) {
serverError({
component: "/functions/backend/setUserSchemaData",
message: error.message,
});
return false;
}
}
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */
/** ****************************************************************************** */