datasquirel/package-shared/api-paths/functions/delete-result.ts
2025-12-22 07:18:57 +01:00

27 lines
673 B
TypeScript

import { APIPathsCrudParams, APIResponseObject } from "../../types";
import dsqlCrud from "../../utils/data-fetching/crud";
export default async function <
T extends { [k: string]: any } = { [k: string]: any }
>({
table,
body,
targetId,
}: APIPathsCrudParams<T>): Promise<APIResponseObject> {
if (!targetId && !body?.searchQuery) {
throw new Error(
`Target ID or \`searchQuery\` field is required to delete Data.`
);
}
const DELETE_RESLT = await dsqlCrud({
...body?.crudParams,
action: "delete",
table,
query: body?.searchQuery,
targetId,
});
return DELETE_RESLT;
}