30 lines
994 B
TypeScript
30 lines
994 B
TypeScript
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;
|
|
}
|