Updates
This commit is contained in:
@@ -14,7 +14,7 @@ import putResult from "./functions/put-result";
|
||||
import deleteResult from "./functions/delete-result";
|
||||
|
||||
export default async function apiCrudHandler<
|
||||
T extends { [k: string]: any } = { [k: string]: any }
|
||||
T extends { [k: string]: any } = { [k: string]: any },
|
||||
>(params: APIPathsParams<T>): Promise<APIResponseObject> {
|
||||
try {
|
||||
const { auth, method } = params;
|
||||
@@ -42,7 +42,7 @@ export default async function apiCrudHandler<
|
||||
|
||||
const finalSearchQuery = _.merge(
|
||||
crudParams.query?.searchQuery,
|
||||
crudParams.body?.searchQuery
|
||||
crudParams.body?.searchQuery,
|
||||
);
|
||||
|
||||
if (finalSearchQuery) {
|
||||
@@ -87,7 +87,7 @@ export default async function apiCrudHandler<
|
||||
}
|
||||
}
|
||||
|
||||
let result: APIResponseObject | undefined;
|
||||
let result: APIResponseObject<any> | undefined;
|
||||
|
||||
switch (method) {
|
||||
case "GET":
|
||||
@@ -107,7 +107,19 @@ export default async function apiCrudHandler<
|
||||
break;
|
||||
}
|
||||
|
||||
await params.postResultsFn?.({ ...crudParams, res: result });
|
||||
await params.postResultsFn?.({
|
||||
..._.omit(crudParams, [
|
||||
"postResultsFnExtraParameters",
|
||||
"postResultsFn",
|
||||
"deleteMiddleware",
|
||||
"putMiddleware",
|
||||
"postMiddleware",
|
||||
"getMiddleware",
|
||||
"auth",
|
||||
]),
|
||||
res: result,
|
||||
...(params.postResultsFnExtraParameters || {}),
|
||||
});
|
||||
|
||||
if (result) {
|
||||
return result;
|
||||
|
||||
@@ -2933,6 +2933,7 @@ export type APIPathsParams<
|
||||
putMiddleware?: APIPathsParamsCrudMiddleware<T>;
|
||||
deleteMiddleware?: APIPathsParamsCrudMiddleware<T>;
|
||||
postResultsFn?: APIPathsPostResulstsFn<T>;
|
||||
postResultsFnExtraParameters?: { [k: string]: any };
|
||||
/** Runs For `POST`, `PUT`, and `DELETE` */
|
||||
crudMiddleware?: APIPathsParamsCrudMiddleware<T>;
|
||||
method: "GET" | "POST" | "PUT" | "DELETE";
|
||||
@@ -2991,11 +2992,24 @@ export type APIPathsParamsCrudMiddleware<
|
||||
|
||||
export type APIPathsPostResulstsFn<
|
||||
T extends { [k: string]: any } = { [k: string]: any },
|
||||
> = (
|
||||
params: APIPathsCrudParams<T> & {
|
||||
res?: APIResponseObject;
|
||||
},
|
||||
) => Promise<void>;
|
||||
P extends { [k: string]: any } = { [k: string]: any },
|
||||
> = (params: APIPathsPostResulstsFnParams<T, P>) => Promise<void>;
|
||||
|
||||
export type APIPathsPostResulstsFnParams<
|
||||
T extends { [k: string]: any } = { [k: string]: any },
|
||||
P extends { [k: string]: any } = { [k: string]: any },
|
||||
> = Omit<
|
||||
APIPathsCrudParams<T>,
|
||||
| "postResultsFnExtraParameters"
|
||||
| "postResultsFn"
|
||||
| "deleteMiddleware"
|
||||
| "putMiddleware"
|
||||
| "postMiddleware"
|
||||
| "getMiddleware"
|
||||
| "auth"
|
||||
> & {
|
||||
res?: APIResponseObject<T>;
|
||||
} & P;
|
||||
|
||||
export type APIPathsParamsAllowedTable = {
|
||||
table: string;
|
||||
|
||||
Reference in New Issue
Block a user