This commit is contained in:
2025-12-22 07:18:57 +01:00
parent 0d9f313dc0
commit cfcd08680f
46 changed files with 1338 additions and 98 deletions
@@ -0,0 +1,26 @@
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;
}
@@ -0,0 +1,29 @@
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;
}
@@ -0,0 +1,15 @@
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 }: APIPathsCrudParams<T>): Promise<APIResponseObject> {
const POST_RESULT = await dsqlCrud({
...body?.crudParams,
action: "insert",
table,
data: body?.data,
});
return POST_RESULT;
}
@@ -0,0 +1,27 @@
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 update Data.`
);
}
const PUT_RESULT = await dsqlCrud({
...body?.crudParams,
action: "update",
table,
data: body?.data,
query: body?.searchQuery,
targetId,
});
return PUT_RESULT;
}