This commit is contained in:
2025-12-26 09:13:47 +01:00
parent b02399c64d
commit d7cef41552
25 changed files with 68 additions and 51 deletions
+3 -5
View File
@@ -1,10 +1,8 @@
import path from "path";
import fs from "fs";
import grabHostNames from "../../utils/grab-host-names";
import apiGetUser from "../../functions/api/users/api-get-user";
import {
APIGetUserFunctionParams,
GetUserFunctionReturn,
APIResponseObject,
GetUserParams,
} from "../../types";
import grabUserDSQLAPIPath from "../../utils/backend/users/grab-api-path";
@@ -21,7 +19,7 @@ export default async function getUser({
apiVersion = "v1",
dbUserId,
selectAll,
}: GetUserParams): Promise<GetUserFunctionReturn> {
}: GetUserParams): Promise<APIResponseObject> {
/**
* Initialize
*/
@@ -119,5 +117,5 @@ export default async function getUser({
httpsRequest.end();
});
return httpResponse as GetUserFunctionReturn;
return httpResponse as APIResponseObject;
}
+1 -7
View File
@@ -1,11 +1,7 @@
import encrypt from "../../functions/dsql/encrypt";
import apiLoginUser from "../../functions/api/users/api-login";
import getAuthCookieNames from "../../functions/backend/cookies/get-auth-cookie-names";
import { writeAuthFile } from "../../functions/backend/auth/write-auth-files";
import {
APILoginFunctionParams,
APIResponseObject,
DATASQUIREL_LoggedInUser,
LoginUserParam,
} from "../../types";
import debugLog from "../../utils/logging/debug-log";
@@ -21,9 +17,7 @@ function debugFn(log: any, label?: string) {
/**
* # Login A user
*/
export default async function loginUser<
T extends DATASQUIREL_LoggedInUser = DATASQUIREL_LoggedInUser
>({
export default async function loginUser({
apiKey,
payload,
database,
@@ -137,7 +137,7 @@ export default async function queryDSQLAPI<T = { [k: string]: any }>({
response.on("error", (err) => {
resolve({
success: false,
payload: undefined,
singleRes: undefined,
msg: `An error occurred on the response`,
error: err.message,
errorData: { requestOptions, grabedHostNames },
@@ -149,7 +149,7 @@ export default async function queryDSQLAPI<T = { [k: string]: any }>({
httpsRequest.on("error", (err) => {
resolve({
success: false,
payload: undefined,
singleRes: undefined,
msg: `An error occurred while making the request`,
error: err.message,
errorData: {
@@ -169,7 +169,7 @@ export default async function queryDSQLAPI<T = { [k: string]: any }>({
} catch (error: any) {
return {
success: false,
payload: undefined,
singleRes: undefined,
msg: `Request Failed`,
error: error.message,
};
@@ -1,7 +1,4 @@
import {
APIGetUserFunctionParams,
GetUserFunctionReturn,
} from "../../../types";
import { APIGetUserFunctionParams, APIResponseObject } from "../../../types";
import grabDbFullName from "../../../utils/grab-db-full-name";
import dbHandler from "../../backend/dbHandler";
@@ -14,7 +11,7 @@ export default async function apiGetUser({
userId,
dbUserId,
selectAll,
}: APIGetUserFunctionParams): Promise<GetUserFunctionReturn> {
}: APIGetUserFunctionParams): Promise<APIResponseObject> {
const finalDbName = grabDbFullName({ dbName: database, userId: dbUserId });
const selectFields = selectAll ? "*" : fields?.[0] ? fields.join(",") : "*";
@@ -101,7 +101,7 @@ export default async function addDbEntry<
if (duplicateValue?.[0] && !update) {
return {
success: false,
payload: undefined,
postInsertReturn: undefined,
msg: "Duplicate entry found",
};
} else if (duplicateValue?.[0] && update) {
@@ -222,7 +222,7 @@ export default async function addDbEntry<
return {
success: Boolean(newInsert?.insertId),
payload: newInsert,
postInsertReturn: newInsert,
queryObject: {
sql: query,
params: finalQueryValues,
@@ -275,7 +275,7 @@ export default async function addDbEntry<
return {
success: Boolean(newInsert?.insertId),
payload: newInsert,
postInsertReturn: newInsert,
queryObject: {
sql: format(query),
params: finalQueryValues,
@@ -284,7 +284,7 @@ export default async function addDbEntry<
} else {
return {
success: false,
payload: undefined,
postInsertReturn: undefined,
msg: "No data provided",
};
}
@@ -56,7 +56,7 @@ export default async function updateDbEntry<
if (!data || !Object.keys(data).length) {
return {
success: false,
payload: undefined,
postInsertReturn: undefined,
msg: "No data provided",
};
}
+2 -2
View File
@@ -128,7 +128,7 @@ export type DSQL_DATASQUIREL_USER_DATABASES = {
active_clone_parent_db?: string;
active_clone_parent_db_id?: number;
active_data?: number;
collation?: string;
collation?: "utf8mb4_bin" | "utf8mb4_unicode_520_ci";
last_checked_date_code?: number;
date_created?: string;
date_created_code?: number;
@@ -153,7 +153,7 @@ export type DSQL_DATASQUIREL_USER_DATABASE_TABLES = {
child_table_parent_database_schema_id?: number;
child_table_parent_table_schema_id?: number;
active_data?: 0 | 1;
collation?: string;
collation?: "utf8mb4_bin" | "utf8mb4_unicode_520_ci";
last_checked_date_code?: number;
date_created?: string;
date_created_code?: number;
+2
View File
@@ -1687,6 +1687,8 @@ export type APIResponseObject<
success: boolean;
payload?: T[] | null;
singleRes?: T | null;
stringRes?: string | null;
numberRes?: number | null;
postInsertReturn?: PostInsertReturn | null;
payloadBase64?: string;
payloadThumbnailBase64?: string;
@@ -125,6 +125,13 @@ export default async function <
return {
success: isSuccess,
payload: isSuccess ? (countOnly ? null : parsedRes) : null,
singleRes: isSuccess
? countOnly
? null
: Array.isArray(parsedRes) && parsedRes.length == 1
? parsedRes[0]
: null
: null,
batchPayload: isSuccess ? (countOnly ? null : parsedBatchRes) : null,
error: isSuccess
? undefined
+3 -1
View File
@@ -48,7 +48,9 @@ export default async function dsqlCrud<
})
: undefined;
const whereClause = queryObject?.string.replace(/^.*?( WHERE )/, "$1");
const whereClause = queryObject?.string?.match(/ WHERE /)
? queryObject.string.replace(/^.*?( WHERE )/, "$1")
: undefined;
const whereClauseObject = whereClause
? {