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

30 lines
782 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,
query,
allowedTable,
url,
}: APIPathsCrudParams<T>): Promise<APIResponseObject> {
if (
(allowedTable?.allowedFields || allowedTable?.disallowedFields) &&
!query?.searchQuery?.selectFields?.[0]
) {
throw new Error(
`Please specify fields to select! Use the \`selectFields\` option in the query object`
);
}
const GET_RESULT = await dsqlCrud({
...query?.crudParams,
action: "get",
table,
query: query?.searchQuery,
});
return GET_RESULT;
}