This commit is contained in:
Tben
2023-08-12 16:46:00 +01:00
parent da559d13ff
commit cb195616b3
27 changed files with 727 additions and 564 deletions
+35 -4
View File
@@ -1,9 +1,14 @@
// @ts-check
/**
* ==============================================================================
* Imports
* ==============================================================================
*/
const https = require("https");
const path = require("path");
const fs = require("fs");
const localAddUser = require("../engine/user/add-user");
/** ****************************************************************************** */
/** ****************************************************************************** */
@@ -20,10 +25,10 @@ const https = require("https");
/**
* @typedef {object} UserDataPayload
* @property {!string} first_name - First Name *Required
* @property {!string} last_name - Last Name *Required
* @property {!string} email - Email *Required
* @property {!string} password - Password *Required
* @property {string} first_name - First Name *Required
* @property {string} last_name - Last Name *Required
* @property {string} email - Email *Required
* @property {string} password - Password *Required
* @property {string?} username - Username (Optional)
*/
@@ -40,6 +45,32 @@ const https = require("https");
* @returns { Promise<FunctionReturn> }
*/
async function addUser({ key, payload, database }) {
/**
* Check for local DB settings
*
* @description Look for local db settings in `.env` file and by pass the http request if available
*/
const { DSQL_HOST, DSQL_USER, DSQL_PASS, DSQL_DB_NAME, DSQL_KEY, DSQL_REF_DB_NAME, DSQL_FULL_SYNC } = process.env;
if (DSQL_HOST?.match(/./) && DSQL_USER?.match(/./) && DSQL_PASS?.match(/./) && DSQL_DB_NAME?.match(/./)) {
/** @type {import("../types/database-schema.td").DSQL_DatabaseSchemaType | undefined} */
let dbSchema;
try {
const localDbSchemaPath = path.resolve(process.cwd(), "dsql.schema.json");
dbSchema = JSON.parse(fs.readFileSync(localDbSchemaPath, "utf8"));
} catch (error) {}
console.log("Reading from local database ...");
if (dbSchema) {
return await localAddUser({
dbSchema: dbSchema,
payload: payload,
});
}
}
/**
* Make https request
*
+7
View File
@@ -44,6 +44,13 @@ const https = require("https");
* @returns { Promise<FunctionReturn>}
*/
async function getUser({ key, userId, database, fields }) {
/**
* Check for local DB settings
*
* @description Look for local db settings in `.env` file and by pass the http request if available
*/
const { DSQL_HOST, DSQL_USER, DSQL_PASS, DSQL_DB_NAME, DSQL_KEY, DSQL_REF_DB_NAME, DSQL_FULL_SYNC } = process.env;
/**
* Make https request
*
+7
View File
@@ -78,6 +78,13 @@ async function loginUser({ key, payload, database, additionalFields, response, e
msg: "Encryption Salt must be at least 8 characters",
};
/**
* Check for local DB settings
*
* @description Look for local db settings in `.env` file and by pass the http request if available
*/
const { DSQL_HOST, DSQL_USER, DSQL_PASS, DSQL_DB_NAME, DSQL_KEY, DSQL_REF_DB_NAME, DSQL_FULL_SYNC } = process.env;
/**
* Make https request
*
+7
View File
@@ -66,6 +66,13 @@ async function reauthUser({ key, database, response, request, level, encryptionK
};
}
/**
* Check for local DB settings
*
* @description Look for local db settings in `.env` file and by pass the http request if available
*/
const { DSQL_HOST, DSQL_USER, DSQL_PASS, DSQL_DB_NAME, DSQL_KEY, DSQL_REF_DB_NAME, DSQL_FULL_SYNC } = process.env;
/**
* Make https request
*
+11
View File
@@ -110,6 +110,17 @@ async function githubAuth({ key, code, email, database, clientId, clientSecret,
////////////////////////////////////////
////////////////////////////////////////
/**
* Check for local DB settings
*
* @description Look for local db settings in `.env` file and by pass the http request if available
*/
const { DSQL_HOST, DSQL_USER, DSQL_PASS, DSQL_DB_NAME, DSQL_KEY, DSQL_REF_DB_NAME, DSQL_FULL_SYNC } = process.env;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Make https request
*
+11
View File
@@ -108,6 +108,17 @@ async function googleAuth({ key, token, database, clientId, response, encryption
////////////////////////////////////////
////////////////////////////////////////
/**
* Check for local DB settings
*
* @description Look for local db settings in `.env` file and by pass the http request if available
*/
const { DSQL_HOST, DSQL_USER, DSQL_PASS, DSQL_DB_NAME, DSQL_KEY, DSQL_REF_DB_NAME, DSQL_FULL_SYNC } = process.env;
////////////////////////////////////////
////////////////////////////////////////
////////////////////////////////////////
/**
* Make https request
*
+7
View File
@@ -32,6 +32,13 @@ const https = require("https");
* @returns { Promise<FunctionReturn>}
*/
async function updateUser({ key, payload, database }) {
/**
* Check for local DB settings
*
* @description Look for local db settings in `.env` file and by pass the http request if available
*/
const { DSQL_HOST, DSQL_USER, DSQL_PASS, DSQL_DB_NAME, DSQL_KEY, DSQL_REF_DB_NAME, DSQL_FULL_SYNC } = process.env;
/**
* Make https request
*