44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
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;
|
|
apiKey?: string;
|
|
/**
|
|
* # Query datasquirel.com
|
|
*/
|
|
useDefault?: boolean;
|
|
};
|
|
|
|
export default async function apiCrudGET<
|
|
T extends { [key: string]: any } = { [key: string]: any }
|
|
>({
|
|
dbName,
|
|
tableName,
|
|
query,
|
|
targetId,
|
|
apiKey,
|
|
useDefault,
|
|
}: 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,
|
|
apiKey,
|
|
useDefault,
|
|
});
|
|
|
|
return GET_RES;
|
|
}
|