This commit is contained in:
Benjamin Toby
2025-07-05 14:59:30 +01:00
parent 6e334c2525
commit 7e8bb37c09
526 changed files with 17560 additions and 11386 deletions
+29
View File
@@ -0,0 +1,29 @@
import path from "path";
import queryDSQLAPI from "../../functions/api/query-dsql-api";
import { DsqlCrudQueryObject, SQLDeleteData } from "../../types";
import grabAPIBasePath from "../../utils/grab-api-base-path";
type Params<T extends { [key: string]: any } = { [key: string]: any }> = {
dbName: string;
tableName: string;
deleteSpec?: T & { deleteKeyValues?: SQLDeleteData<T>[] };
targetID?: string | number;
};
export default async function apiCrudDELETE<
T extends { [key: string]: any } = { [key: string]: any }
>({ dbName, tableName, deleteSpec, targetID }: Params<T>) {
const basePath = grabAPIBasePath({ paradigm: "crud" });
const finalID = typeof targetID === "number" ? String(targetID) : targetID;
const finalPath = path.join(basePath, dbName, tableName, finalID || "");
const GET_RES = await queryDSQLAPI<DsqlCrudQueryObject<T>>({
method: "DELETE",
path: finalPath,
body: deleteSpec,
});
return GET_RES;
}
+34
View File
@@ -0,0 +1,34 @@
import path from "path";
import queryDSQLAPI from "../../functions/api/query-dsql-api";
import { APIResponseObject, DsqlCrudQueryObject } from "../../types";
import grabAPIBasePath from "../../utils/grab-api-base-path";
type Params<T extends { [key: string]: any } = { [key: string]: any }> = {
dbName: string;
tableName: string;
query?: DsqlCrudQueryObject<T>;
targetId?: string | number;
};
export default async function apiCrudGET<
T extends { [key: string]: any } = { [key: string]: any }
>({
dbName,
tableName,
query,
targetId,
}: Params<T>): Promise<APIResponseObject> {
const basePath = grabAPIBasePath({ paradigm: "crud" });
const finalID = typeof targetId === "number" ? String(targetId) : targetId;
const finalPath = path.join(basePath, dbName, tableName, finalID || "");
const GET_RES = await queryDSQLAPI<DsqlCrudQueryObject<T>>({
method: "GET",
path: finalPath,
query,
});
return GET_RES;
}
+14
View File
@@ -0,0 +1,14 @@
import apiCrudGET from "./get";
import apiCrudPOST from "./post";
import apiCrudPUT from "./put";
import apiCrudDELETE from "./delete";
const crud = {
get: apiCrudGET,
insert: apiCrudPOST,
update: apiCrudPUT,
delete: apiCrudDELETE,
options: async () => {},
};
export default crud;
+42
View File
@@ -0,0 +1,42 @@
import path from "path";
import queryDSQLAPI from "../../functions/api/query-dsql-api";
import { APIResponseObject, DsqlCrudQueryObject } from "../../types";
import grabAPIBasePath from "../../utils/grab-api-base-path";
export type APICrudPostParams<
T extends { [key: string]: any } = { [key: string]: any }
> = {
dbName: string;
tableName: string;
body: T;
update?: boolean;
};
export default async function apiCrudPOST<
T extends { [key: string]: any } = { [key: string]: any }
>({
dbName,
tableName,
body,
update,
}: APICrudPostParams<T>): Promise<APIResponseObject> {
const basePath = grabAPIBasePath({ paradigm: "crud" });
const passedID = body.id as string | number | undefined;
const finalID = update
? typeof passedID === "number"
? String(passedID)
: passedID
: undefined;
const finalPath = path.join(basePath, dbName, tableName, finalID || "");
const GET_RES = await queryDSQLAPI<DsqlCrudQueryObject<T>>({
method: update ? "PUT" : "POST",
path: finalPath,
body,
});
return GET_RES;
}
+25
View File
@@ -0,0 +1,25 @@
import apiCrudPOST, { APICrudPostParams } from "./post";
type Params<T extends { [key: string]: any } = { [key: string]: any }> = Omit<
APICrudPostParams<T>,
"update"
> & {
targetID: string | number;
};
export default async function apiCrudPUT<
T extends { [key: string]: any } = { [key: string]: any }
>({ dbName, tableName, body, targetID }: Params<T>) {
const updatedBody = { ...body } as any;
if (targetID) {
updatedBody["id"] = targetID;
}
return await apiCrudPOST({
dbName,
tableName,
body: updatedBody,
update: true,
});
}
+32
View File
@@ -0,0 +1,32 @@
import queryDSQLAPI from "../../functions/api/query-dsql-api";
import { APIResponseObject } from "../../types";
import { DSQL_DATASQUIREL_USER_MEDIA } from "../../types/dsql";
import path from "path";
import grabAPIBasePath from "../../utils/grab-api-base-path";
export default async function apiMediaDELETE(params: {
mediaID?: string | number;
}): Promise<
APIResponseObject<
DSQL_DATASQUIREL_USER_MEDIA | DSQL_DATASQUIREL_USER_MEDIA[]
>
> {
const basePath = grabAPIBasePath({ paradigm: "media" });
const mediaID = params.mediaID
? typeof params.mediaID === "number"
? String(params.mediaID)
: params.mediaID
: undefined;
const finalPath = path.join(basePath, mediaID || "");
const DELETE_MEDIA_RES = await queryDSQLAPI({
method: "DELETE",
path: finalPath,
});
return DELETE_MEDIA_RES as APIResponseObject<
DSQL_DATASQUIREL_USER_MEDIA | DSQL_DATASQUIREL_USER_MEDIA[]
>;
}
+33
View File
@@ -0,0 +1,33 @@
import queryDSQLAPI from "../../functions/api/query-dsql-api";
import { APIGetMediaParams, APIResponseObject } from "../../types";
import path from "path";
import { DSQL_DATASQUIREL_USER_MEDIA } from "../../types/dsql";
import grabAPIBasePath from "../../utils/grab-api-base-path";
export default async function apiMediaGET(
params: APIGetMediaParams
): Promise<
APIResponseObject<
DSQL_DATASQUIREL_USER_MEDIA | DSQL_DATASQUIREL_USER_MEDIA[]
>
> {
const basePath = grabAPIBasePath({ paradigm: "media" });
const mediaID = params.mediaID
? typeof params.mediaID === "number"
? String(params.mediaID)
: params.mediaID
: undefined;
const finalPath = path.join(basePath, mediaID || "");
const GET_MEDIA_RES = await queryDSQLAPI<APIGetMediaParams>({
method: "GET",
path: finalPath,
query: params,
});
return GET_MEDIA_RES as APIResponseObject<
DSQL_DATASQUIREL_USER_MEDIA | DSQL_DATASQUIREL_USER_MEDIA[]
>;
}
+11
View File
@@ -0,0 +1,11 @@
import apiMediaGET from "./get";
import apiMediaPOST from "./post";
import apiMediaDELETE from "./delete";
const media = {
get: apiMediaGET,
add: apiMediaPOST,
delete: apiMediaDELETE,
};
export default media;
+24
View File
@@ -0,0 +1,24 @@
import queryDSQLAPI from "../../functions/api/query-dsql-api";
import { AddMediaAPIBody, APIResponseObject } from "../../types";
import { DSQL_DATASQUIREL_USER_MEDIA } from "../../types/dsql";
import grabAPIBasePath from "../../utils/grab-api-base-path";
export default async function apiMediaPOST(
params: AddMediaAPIBody
): Promise<
APIResponseObject<
DSQL_DATASQUIREL_USER_MEDIA | DSQL_DATASQUIREL_USER_MEDIA[]
>
> {
const basePath = grabAPIBasePath({ paradigm: "media" });
const POST_MEDIA_RES = await queryDSQLAPI<AddMediaAPIBody>({
method: "POST",
path: basePath,
body: params,
});
return POST_MEDIA_RES as APIResponseObject<
DSQL_DATASQUIREL_USER_MEDIA | DSQL_DATASQUIREL_USER_MEDIA[]
>;
}
+3
View File
@@ -0,0 +1,3 @@
const user = {};
export default user;