This commit is contained in:
Benjamin Toby
2025-02-19 08:39:03 +01:00
parent 8b3553fcd5
commit 2e0b6d0a70
26 changed files with 387 additions and 14 deletions
@@ -26,9 +26,7 @@ export default async function googleLogin({
serverRes,
loginFailureReason,
}: Param) {
const client = new OAuth2Client(
process.env.NEXT_PUBLIC_DSQL_GOOGLE_CLIENT_ID
);
const client = new OAuth2Client(process.env.DSQL_GOOGLE_CLIENT_ID);
let isGoogleAuthValid = false;
let newFoundUser = null;
@@ -39,7 +37,7 @@ export default async function googleLogin({
try {
const ticket = await client.verifyIdToken({
idToken: reqBody.token,
audience: process.env.NEXT_PUBLIC_DSQL_GOOGLE_CLIENT_ID, // Specify the CLIENT_ID of the app that accesses the backend
audience: process.env.DSQL_GOOGLE_CLIENT_ID, // Specify the CLIENT_ID of the app that accesses the backend
// Or, if multiple clients access the backend:
//[CLIENT_ID_1, CLIENT_ID_2, CLIENT_ID_3]
});
@@ -0,0 +1,44 @@
import getQueue from "./get-queue";
import {
DSQL_DATASQUIREL_PROCESS_QUEUE,
DsqlTables,
} from "../../../types/dsql";
import dsqlCrud from "../../../utils/data-fetching/crud";
import numberfy from "../../../utils/numberfy";
type Param = {
queue: DSQL_DATASQUIREL_PROCESS_QUEUE;
userId: string | number;
dummy?: boolean;
};
export default async function addQueue({ queue, userId, dummy }: Param) {
const tableName: (typeof DsqlTables)[number] = "process_queue";
const existingQueueRes = dummy
? undefined
: ((await getQueue({
query: {
query: {
user_id: {
value: String(userId),
},
job_type: {
value: String(queue.job_type),
},
},
},
})) as DSQL_DATASQUIREL_PROCESS_QUEUE[] | undefined);
const existingQueue = existingQueueRes?.[0];
if (existingQueue?.id && !dummy) return undefined;
const addQueueRes = await dsqlCrud<DSQL_DATASQUIREL_PROCESS_QUEUE>({
action: "insert",
table: tableName,
data: { ...queue, user_id: numberfy(userId) },
});
return addQueueRes;
}
@@ -0,0 +1,29 @@
import dsqlCrud from "../../../utils/data-fetching/crud";
import getQueue from "./get-queue";
import {
DSQL_DATASQUIREL_PROCESS_QUEUE,
DsqlTables,
} from "../../../types/dsql";
type Param = {
queueId: string | number;
userId: string | number;
};
export default async function deleteQueue({ queueId, userId }: Param) {
const tableName: (typeof DsqlTables)[number] = "process_queue";
const existingQueue = (await getQueue({ userId, queueId })) as
| DSQL_DATASQUIREL_PROCESS_QUEUE
| undefined;
if (!existingQueue?.id) return false;
const deleteQueueRes = await dsqlCrud<DSQL_DATASQUIREL_PROCESS_QUEUE>({
action: "delete",
table: tableName,
targetId: existingQueue.id,
});
return Boolean(deleteQueueRes?.success);
}
@@ -0,0 +1,53 @@
import {
DSQL_DATASQUIREL_PROCESS_QUEUE,
DsqlTables,
} from "../../../types/dsql";
import dsqlCrud from "../../../utils/data-fetching/crud";
import { DsqlCrudQueryObject, ServerQueryQueryObject } from "../../../types";
type Param = {
queueId?: string | number;
userId?: string | number;
query?: DsqlCrudQueryObject<DSQL_DATASQUIREL_PROCESS_QUEUE>;
single?: boolean;
};
export default async function getQueue({
queueId,
userId,
query,
single,
}: Param) {
const tableName: (typeof DsqlTables)[number] = "process_queue";
let queryQuery: ServerQueryQueryObject<DSQL_DATASQUIREL_PROCESS_QUEUE> = {};
if (queueId) {
queryQuery = { ...queryQuery, ...{ id: { value: String(queueId) } } };
}
if (userId) {
queryQuery = {
...queryQuery,
...{ user_id: { value: String(userId) } },
};
}
const getQueue = await dsqlCrud<DSQL_DATASQUIREL_PROCESS_QUEUE>({
action: "get",
table: tableName,
query: {
...query,
query: {
...query?.query,
...queryQuery,
},
},
});
const queuePayload = getQueue?.payload as
| DSQL_DATASQUIREL_PROCESS_QUEUE[]
| undefined;
return queueId || single ? queuePayload?.[0] : queuePayload;
}
@@ -0,0 +1,23 @@
import dsqlCrud from "../../../utils/data-fetching/crud";
import {
DSQL_DATASQUIREL_PROCESS_QUEUE,
DsqlTables,
} from "../../../types/dsql";
type Param = {
queueId: string | number;
queue: DSQL_DATASQUIREL_PROCESS_QUEUE;
};
export default async function updateQueue({ queueId, queue }: Param) {
const tableName: (typeof DsqlTables)[number] = "process_queue";
const updateQueueRes = await dsqlCrud<DSQL_DATASQUIREL_PROCESS_QUEUE>({
action: "update",
table: tableName,
targetId: queueId,
data: queue,
});
return Boolean(updateQueueRes?.success);
}
@@ -26,7 +26,7 @@ export default function sqlGenerator<
>({ tableName, genObject, dbFullName }: Param<T>): Return {
if (!genObject) return undefined;
const finalQuery = genObject.query ? genObject.query : undefined;
const finalQuery = genObject?.query ? genObject.query : undefined;
const queryKeys = finalQuery ? Object.keys(finalQuery) : undefined;
@@ -26,7 +26,7 @@ export default async function createDbFromSchema({
userId,
targetDatabase,
dbSchemaData,
}: Param) {
}: Param): Promise<boolean> {
const { userSchemaMainJSONFilePath, mainShemaJSONFilePath } = grabDirNames({
userId,
});
@@ -41,7 +41,7 @@ export default async function createDbFromSchema({
if (!dbSchema) {
console.log("Schema Not Found!");
return;
return false;
}
for (let i = 0; i < dbSchema.length; i++) {
@@ -228,4 +228,6 @@ export default async function createDbFromSchema({
}
}
}
return true;
}
+21
View File
@@ -15,6 +15,7 @@ export const DsqlTables = [
"docs_page_extra_links",
"deleted_api_keys",
"servers",
"process_queue",
] as const
export type DSQL_DATASQUIREL_USERS = {
@@ -320,4 +321,24 @@ export type DSQL_DATASQUIREL_SERVERS = {
date_updated?: string;
date_updated_code?: number;
date_updated_timestamp?: string;
}
export type DSQL_DATASQUIREL_PROCESS_QUEUE = {
id?: number;
uuid?: string;
user_id?: number;
title?: string;
job_type?: string;
data?: string;
running?: number;
server_id?: number;
error?: number;
error_message?: string;
success?: number;
date_created?: string;
date_created_code?: number;
date_created_timestamp?: string;
date_updated?: string;
date_updated_code?: number;
date_updated_timestamp?: string;
}
@@ -62,6 +62,11 @@ export default function grabDirNames(param?: Param) {
? path.join(userPrivateSQLExportsDir, userPrivateDbImportZipFileName)
: undefined;
const dbNginxLoadBalancerConfigFile = path.join(
appDir,
"docker/mariadb/load-balancer/config/template/nginx.conf"
);
return {
schemasDir,
userDirPath,
@@ -80,5 +85,6 @@ export default function grabDirNames(param?: Param) {
userPrivateDbExportZipFilePath,
userPrivateDbImportZipFileName,
userPrivateDbImportZipFilePath,
dbNginxLoadBalancerConfigFile,
};
}