Bug Fixes
This commit is contained in:
@@ -1,15 +1,17 @@
|
||||
// @ts-check
|
||||
|
||||
const fs = require("fs");
|
||||
require("dotenv").config({ path: "../../../.env" });
|
||||
const hashPassword = require("datasquirel/functions/hashPassword");
|
||||
const path = require("path");
|
||||
require("dotenv").config({ path: "../../../.env" });
|
||||
const fs = require("fs");
|
||||
const hashPassword = require("datasquirel/functions/hashPassword");
|
||||
const { execSync } = require("child_process");
|
||||
const encrypt = require("../../../package-shared/functions/backend/encrypt");
|
||||
const addMariadbUser = require("../../../package-shared/functions/backend/addMariadbUser");
|
||||
const DB_HANDLER = require("../../../package-shared/utils/backend/global-db/DB_HANDLER");
|
||||
const addDbEntry = require("../../../package-shared/functions/backend/db/addDbEntry");
|
||||
const updateDbEntry = require("../../../package-shared/functions/backend/db/updateDbEntry");
|
||||
const EJSON = require("../../../package-shared/utils/ejson");
|
||||
|
||||
const tmpDir = process.argv[process.argv.length - 1];
|
||||
|
||||
/**
|
||||
* # Create New User
|
||||
@@ -21,9 +23,17 @@ async function createUser() {
|
||||
* @description Check if request body is valid
|
||||
*/
|
||||
try {
|
||||
const userObj = JSON.parse(
|
||||
fs.readFileSync(path.resolve(__dirname, "./new-user.json"), "utf-8")
|
||||
);
|
||||
const isTmpDir = Boolean(tmpDir?.match(/\.json$/));
|
||||
const targetPath = isTmpDir
|
||||
? path.resolve(process.cwd(), tmpDir)
|
||||
: path.resolve(__dirname, "./new-user.json");
|
||||
|
||||
const userObj = EJSON.parse(fs.readFileSync(targetPath, "utf-8"));
|
||||
|
||||
if (typeof userObj !== "object" || Array.isArray(userObj))
|
||||
throw new Error("User Object Invalid!");
|
||||
|
||||
console.log("userObj", userObj);
|
||||
|
||||
const ROOT_DIR = path.resolve(__dirname, "../../../");
|
||||
|
||||
@@ -37,7 +47,6 @@ async function createUser() {
|
||||
const email = userObj.email;
|
||||
const password = userObj.password;
|
||||
const username = userObj.username;
|
||||
const id = userObj.id || undefined;
|
||||
|
||||
if (!email?.match(/.*@.*\..*/)) return false;
|
||||
|
||||
@@ -90,7 +99,7 @@ async function createUser() {
|
||||
*
|
||||
* @description Create new user folder and file
|
||||
*/
|
||||
let newUserSchemaFolderPath = `./jsonData/dbSchemas/users/user-${newUser.insertId}`;
|
||||
let newUserSchemaFolderPath = `${process.env.DSQL_USER_DB_SCHEMA_PATH}/user-${newUser.insertId}`;
|
||||
let newUserMediaFolderPath = path.join(
|
||||
STATIC_ROOT,
|
||||
`images/user-images/user-${newUser.insertId}`
|
||||
@@ -149,6 +158,12 @@ async function createUser() {
|
||||
},
|
||||
});
|
||||
|
||||
if (isTmpDir) {
|
||||
try {
|
||||
fs.unlinkSync(path.resolve(process.cwd(), tmpDir));
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log(`Error in creating user => ${error.message}`);
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
// @ts-check
|
||||
|
||||
const fs = require("fs");
|
||||
require("dotenv").config({ path: "../../../.env" });
|
||||
const hashPassword = require("datasquirel/functions/hashPassword");
|
||||
const path = require("path");
|
||||
const { execSync } = require("child_process");
|
||||
const encrypt = require("../../../package-shared/functions/backend/encrypt");
|
||||
const addMariadbUser = require("../../../package-shared/functions/backend/addMariadbUser");
|
||||
const DB_HANDLER = require("../../../package-shared/utils/backend/global-db/DB_HANDLER");
|
||||
const addDbEntry = require("../../../package-shared/functions/backend/db/addDbEntry");
|
||||
require("dotenv").config({ path: "../../../.env" });
|
||||
const fs = require("fs");
|
||||
const hashPassword = require("datasquirel/functions/hashPassword");
|
||||
const updateDbEntry = require("../../../package-shared/functions/backend/db/updateDbEntry");
|
||||
const EJSON = require("../../../package-shared/utils/ejson");
|
||||
|
||||
const tmpDir = process.argv[process.argv.length - 1];
|
||||
|
||||
/**
|
||||
* # Create New User
|
||||
@@ -21,9 +19,14 @@ async function createUser() {
|
||||
* @description Check if request body is valid
|
||||
*/
|
||||
try {
|
||||
const updateUserObj = JSON.parse(
|
||||
fs.readFileSync(path.resolve(__dirname, "./new-user.json"), "utf-8")
|
||||
);
|
||||
const isTmpDir = Boolean(tmpDir?.match(/\.json$/));
|
||||
const targetPath = isTmpDir
|
||||
? path.resolve(process.cwd(), tmpDir)
|
||||
: path.resolve(__dirname, "./update-user.json");
|
||||
const updateUserObj = EJSON.parse(fs.readFileSync(targetPath, "utf-8"));
|
||||
|
||||
if (typeof updateUserObj !== "object" || Array.isArray(updateUserObj))
|
||||
throw new Error("Update User Object Invalid!");
|
||||
|
||||
let hashedPassword = updateUserObj.password
|
||||
? hashPassword({
|
||||
@@ -48,6 +51,12 @@ async function createUser() {
|
||||
|
||||
if (!newUser?.affectedRows) return false;
|
||||
|
||||
if (isTmpDir) {
|
||||
try {
|
||||
fs.unlinkSync(path.resolve(process.cwd(), tmpDir));
|
||||
} catch (error) {}
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (/** @type {any} */ error) {
|
||||
console.log(`Error in creating user => ${error.message}`);
|
||||
|
||||
Reference in New Issue
Block a user