Major refactoring: Add user id to API routes
This commit is contained in:
+13
-8
@@ -12,12 +12,13 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
* ==============================================================================
|
||||
* @async
|
||||
*
|
||||
* @param {object} props - Single object passed
|
||||
* @param {string} props.key - FULL ACCESS API Key
|
||||
* @param {string} props.database - Database Name
|
||||
* @param {import("../package-shared/types").UserDataPayload} props.payload - User Data Payload
|
||||
* @param {string} props.encryptionKey
|
||||
* @param {string} [props.encryptionSalt]
|
||||
* @param {object} param - Single object passed
|
||||
* @param {string} param.key - FULL ACCESS API Key
|
||||
* @param {string} param.database - Database Name
|
||||
* @param {import("../package-shared/types").UserDataPayload} param.payload - User Data Payload
|
||||
* @param {string} param.encryptionKey
|
||||
* @param {string} [param.encryptionSalt]
|
||||
* @param {boolean} [param.user_id] - User ID
|
||||
*
|
||||
* @returns { Promise<import("../package-shared/types").AddUserFunctionReturn> }
|
||||
*/
|
||||
@@ -27,6 +28,7 @@ async function addUser({
|
||||
database,
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
user_id,
|
||||
}) {
|
||||
/**
|
||||
* Check for local DB settings
|
||||
@@ -43,7 +45,8 @@ async function addUser({
|
||||
DSQL_FULL_SYNC,
|
||||
} = process.env;
|
||||
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
if (
|
||||
DSQL_HOST?.match(/./) &&
|
||||
@@ -97,7 +100,9 @@ async function addUser({
|
||||
},
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/add-user`,
|
||||
path: `/api/user/${
|
||||
user_id || grabedHostNames.user_id
|
||||
}/add-user`,
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
+7
-3
@@ -30,10 +30,11 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
* @param {String} params.database - Target Database
|
||||
* @param {number} params.userId - user id
|
||||
* @param {string[]} [params.fields] - fields to select
|
||||
* @param {boolean} [params.user_id] - User ID
|
||||
*
|
||||
* @returns { Promise<import("../package-shared/types").GetUserFunctionReturn>}
|
||||
*/
|
||||
async function getUser({ key, userId, database, fields }) {
|
||||
async function getUser({ key, userId, database, fields, user_id }) {
|
||||
/**
|
||||
* Initialize
|
||||
*/
|
||||
@@ -63,7 +64,8 @@ async function getUser({ key, userId, database, fields }) {
|
||||
fields: [...new Set(updatedFields)],
|
||||
});
|
||||
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
/**
|
||||
* Check for local DB settings
|
||||
@@ -125,7 +127,9 @@ async function getUser({ key, userId, database, fields }) {
|
||||
},
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/get-user`,
|
||||
path: `/api/user/${
|
||||
user_id || grabedHostNames.user_id
|
||||
}/get-user`,
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
+7
-2
@@ -41,6 +41,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
* @param {string} [params.email_login_code] - Email login code
|
||||
* @param {string} [params.temp_code_field] - Database table field name for temporary code
|
||||
* @param {boolean} [params.token] - Send access key as part of response body?
|
||||
* @param {boolean} [params.user_id] - User ID
|
||||
*
|
||||
* @returns { Promise<import("../package-shared/types").AuthenticatedUser>}
|
||||
*/
|
||||
@@ -56,8 +57,10 @@ async function loginUser({
|
||||
email_login_code,
|
||||
temp_code_field,
|
||||
token,
|
||||
user_id,
|
||||
}) {
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
const defaultTempLoginFieldName = "temp_login_code";
|
||||
const emailLoginTempCodeFieldName = email_login
|
||||
@@ -183,7 +186,9 @@ async function loginUser({
|
||||
},
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/login-user`,
|
||||
path: `/api/user/${
|
||||
user_id || grabedHostNames.user_id
|
||||
}/login-user`,
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,6 +38,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
* @param {String} params.encryptionSalt - Encryption Salt
|
||||
* @param {string[]} [params.additionalFields] - Additional Fields to be added to the user object
|
||||
* @param {string} [params.token] - access token to use instead of getting from cookie header
|
||||
* @param {boolean} [params.user_id] - User ID
|
||||
*
|
||||
* @returns { Promise<import("../package-shared/types").ReauthUserFunctionReturn> }
|
||||
*/
|
||||
@@ -51,13 +52,15 @@ async function reauthUser({
|
||||
encryptionSalt,
|
||||
additionalFields,
|
||||
token,
|
||||
user_id,
|
||||
}) {
|
||||
/**
|
||||
* Check Encryption Keys
|
||||
*
|
||||
* @description Check Encryption Keys
|
||||
*/
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
const existingUser = userAuth({
|
||||
database,
|
||||
@@ -146,7 +149,9 @@ async function reauthUser({
|
||||
},
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/reauth-user`,
|
||||
path: `/api/user/${
|
||||
user_id || grabedHostNames.user_id
|
||||
}/reauth-user`,
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,6 +39,7 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
* @param {string} [params.mail_password]
|
||||
* @param {number} [params.mail_port]
|
||||
* @param {string} [params.sender]
|
||||
* @param {boolean} [params.user_id] - User ID
|
||||
*
|
||||
* @returns { Promise<boolean>}
|
||||
*/
|
||||
@@ -54,8 +55,10 @@ async function sendEmailCode({
|
||||
mail_username,
|
||||
mail_port,
|
||||
sender,
|
||||
user_id,
|
||||
}) {
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
const defaultTempLoginFieldName = "temp_login_code";
|
||||
const emailLoginTempCodeFieldName = temp_code_field
|
||||
@@ -176,7 +179,9 @@ async function sendEmailCode({
|
||||
},
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/send-email-code`,
|
||||
path: `/api/user/${
|
||||
user_id || grabedHostNames.user_id
|
||||
}/send-email-code`,
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -45,6 +45,7 @@ const grabHostNames = require("../../package-shared/utils/grab-host-names");
|
||||
* @param {string} params.encryptionKey - Encryption key
|
||||
* @param {string} params.encryptionSalt - Encryption salt
|
||||
* @param {object} [params.additionalFields] - Additional Fields to be added to the user object
|
||||
* @param {boolean} [params.user_id] - User ID
|
||||
*
|
||||
* @returns { Promise<FunctionReturn | undefined> }
|
||||
*/
|
||||
@@ -59,13 +60,15 @@ async function githubAuth({
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
additionalFields,
|
||||
user_id,
|
||||
}) {
|
||||
/**
|
||||
* Check inputs
|
||||
*
|
||||
* @description Check inputs
|
||||
*/
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
if (!key || key?.match(/ /)) {
|
||||
return {
|
||||
@@ -205,7 +208,9 @@ async function githubAuth({
|
||||
},
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/github-login`,
|
||||
path: `/api/user/${
|
||||
user_id || grabedHostNames.user_id
|
||||
}/github-login`,
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,6 +43,7 @@ const grabHostNames = require("../../package-shared/utils/grab-host-names");
|
||||
* @param {string} params.encryptionKey - Encryption key
|
||||
* @param {string} params.encryptionSalt - Encryption salt
|
||||
* @param {object} [params.additionalFields] - Additional Fields to be added to the user object
|
||||
* @param {boolean} [params.user_id] - User ID
|
||||
*
|
||||
* @returns { Promise<FunctionReturn> }
|
||||
*/
|
||||
@@ -55,8 +56,10 @@ async function googleAuth({
|
||||
encryptionKey,
|
||||
encryptionSalt,
|
||||
additionalFields,
|
||||
user_id,
|
||||
}) {
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
/**
|
||||
* Check inputs
|
||||
@@ -201,7 +204,9 @@ async function googleAuth({
|
||||
},
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/google-login`,
|
||||
path: `/api/user/${
|
||||
user_id || grabedHostNames.user_id
|
||||
}/google-login`,
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
@@ -15,10 +15,11 @@ const grabHostNames = require("../package-shared/utils/grab-host-names");
|
||||
* @param {String} params.key - API Key
|
||||
* @param {String} params.database - Target Database
|
||||
* @param {{ id: number } & Object.<string, any>} params.payload - User Object: ID is required
|
||||
* @param {boolean} [params.user_id] - User ID
|
||||
*
|
||||
* @returns { Promise<import("../package-shared/types").UpdateUserFunctionReturn>}
|
||||
*/
|
||||
async function updateUser({ key, payload, database }) {
|
||||
async function updateUser({ key, payload, database, user_id }) {
|
||||
/**
|
||||
* Check for local DB settings
|
||||
*
|
||||
@@ -34,7 +35,8 @@ async function updateUser({ key, payload, database }) {
|
||||
DSQL_FULL_SYNC,
|
||||
} = process.env;
|
||||
|
||||
const { host, port, scheme } = grabHostNames();
|
||||
const grabedHostNames = grabHostNames();
|
||||
const { host, port, scheme } = grabedHostNames;
|
||||
|
||||
if (
|
||||
DSQL_HOST?.match(/./) &&
|
||||
@@ -85,7 +87,9 @@ async function updateUser({ key, payload, database }) {
|
||||
},
|
||||
port,
|
||||
hostname: host,
|
||||
path: `/api/user/update-user`,
|
||||
path: `/api/user/${
|
||||
user_id || grabedHostNames.user_id
|
||||
}/update-user`,
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user