This commit is contained in:
2025-12-31 10:28:52 +01:00
parent 276a0db83b
commit f7a2d6e03a
7 changed files with 51 additions and 14 deletions
+10 -5
View File
@@ -22,7 +22,7 @@ const put_result_1 = __importDefault(require("./functions/put-result"));
const delete_result_1 = __importDefault(require("./functions/delete-result"));
function apiCrudHandler(params) {
return __awaiter(this, void 0, void 0, function* () {
var _a, _b;
var _a, _b, _c;
try {
const { auth, method } = params;
const isAuthorized = yield (auth === null || auth === void 0 ? void 0 : auth());
@@ -72,15 +72,20 @@ function apiCrudHandler(params) {
};
}
}
let result;
switch (method) {
case "GET":
return yield (0, get_result_1.default)(crudParams);
result = yield (0, get_result_1.default)(crudParams);
case "POST":
return yield (0, post_result_1.default)(crudParams);
result = yield (0, post_result_1.default)(crudParams);
case "PUT":
return yield (0, put_result_1.default)(crudParams);
result = yield (0, put_result_1.default)(crudParams);
case "DELETE":
return yield (0, delete_result_1.default)(crudParams);
result = yield (0, delete_result_1.default)(crudParams);
}
yield ((_c = params.postResultsFn) === null || _c === void 0 ? void 0 : _c.call(params, Object.assign(Object.assign({}, crudParams), { res: result })));
if (result) {
return result;
}
return {
success: false,
+2 -2
View File
@@ -130,8 +130,8 @@ function createDbFromSchema(_a) {
* @description Update table if table exists
*/
const updateExistingTable = yield (0, updateTable_1.default)({
dbFullName: dbFullName,
tableName: tableName,
dbFullName,
tableName,
tableFields: fields,
userId,
dbSchema: database,
+12
View File
@@ -2216,6 +2216,7 @@ export type APIPathsParams<T extends {
postMiddleware?: APIPathsParamsCrudMiddleware<T>;
putMiddleware?: APIPathsParamsCrudMiddleware<T>;
deleteMiddleware?: APIPathsParamsCrudMiddleware<T>;
postResultsFn?: APIPathsPostResulstsFn<T>;
/** Runs For `POST`, `PUT`, and `DELETE` */
crudMiddleware?: APIPathsParamsCrudMiddleware<T>;
method: "GET" | "POST" | "PUT" | "DELETE";
@@ -2264,6 +2265,17 @@ export type APIPathsParamsCrudMiddleware<T extends {
table: K;
targetId?: number | string;
}) => Promise<APIPathsBody<T> | undefined>;
export type APIPathsPostResulstsFn<T extends {
[k: string]: any;
} = {
[k: string]: any;
}, K extends string = string> = (params: {
body?: APIPathsBody<T>;
query?: DsqlCrudQueryObject<T>;
table: K;
targetId?: number | string;
res?: APIResponseObject;
}) => Promise<APIPathsBody<T> | undefined>;
export type APIPathsParamsAllowedTable = {
table: string;
allowedFields?: (string | RegExp)[];