diff --git a/dist/package-shared/api-paths/index.js b/dist/package-shared/api-paths/index.js index 0daddae..a4462d7 100644 --- a/dist/package-shared/api-paths/index.js +++ b/dist/package-shared/api-paths/index.js @@ -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, diff --git a/dist/package-shared/shell/createDbFromSchema/index.js b/dist/package-shared/shell/createDbFromSchema/index.js index 5874c25..d7508e1 100644 --- a/dist/package-shared/shell/createDbFromSchema/index.js +++ b/dist/package-shared/shell/createDbFromSchema/index.js @@ -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, diff --git a/dist/package-shared/types/index.d.ts b/dist/package-shared/types/index.d.ts index f3ba01c..9e29d4a 100644 --- a/dist/package-shared/types/index.d.ts +++ b/dist/package-shared/types/index.d.ts @@ -2216,6 +2216,7 @@ export type APIPathsParams; putMiddleware?: APIPathsParamsCrudMiddleware; deleteMiddleware?: APIPathsParamsCrudMiddleware; + postResultsFn?: APIPathsPostResulstsFn; /** Runs For `POST`, `PUT`, and `DELETE` */ crudMiddleware?: APIPathsParamsCrudMiddleware; method: "GET" | "POST" | "PUT" | "DELETE"; @@ -2264,6 +2265,17 @@ export type APIPathsParamsCrudMiddleware Promise | undefined>; +export type APIPathsPostResulstsFn = (params: { + body?: APIPathsBody; + query?: DsqlCrudQueryObject; + table: K; + targetId?: number | string; + res?: APIResponseObject; +}) => Promise | undefined>; export type APIPathsParamsAllowedTable = { table: string; allowedFields?: (string | RegExp)[]; diff --git a/package-shared/api-paths/index.ts b/package-shared/api-paths/index.ts index 8c26821..e8c4a47 100644 --- a/package-shared/api-paths/index.ts +++ b/package-shared/api-paths/index.ts @@ -87,15 +87,23 @@ export default async function apiCrudHandler< } } + let result: APIResponseObject | undefined; + switch (method) { case "GET": - return await getResult(crudParams); + result = await getResult(crudParams); case "POST": - return await postResult(crudParams); + result = await postResult(crudParams); case "PUT": - return await putResult(crudParams); + result = await putResult(crudParams); case "DELETE": - return await deleteResult(crudParams); + result = await deleteResult(crudParams); + } + + await params.postResultsFn?.({ ...crudParams, res: result }); + + if (result) { + return result; } return { diff --git a/package-shared/shell/createDbFromSchema/index.ts b/package-shared/shell/createDbFromSchema/index.ts index 70c5ca1..ea9b01c 100644 --- a/package-shared/shell/createDbFromSchema/index.ts +++ b/package-shared/shell/createDbFromSchema/index.ts @@ -160,8 +160,8 @@ export default async function createDbFromSchema({ * @description Update table if table exists */ const updateExistingTable = await updateTable({ - dbFullName: dbFullName, - tableName: tableName, + dbFullName, + tableName, tableFields: fields, userId, dbSchema: database, diff --git a/package-shared/types/index.ts b/package-shared/types/index.ts index 0c35049..4d5b5df 100644 --- a/package-shared/types/index.ts +++ b/package-shared/types/index.ts @@ -2877,6 +2877,7 @@ export type APIPathsParams< postMiddleware?: APIPathsParamsCrudMiddleware; putMiddleware?: APIPathsParamsCrudMiddleware; deleteMiddleware?: APIPathsParamsCrudMiddleware; + postResultsFn?: APIPathsPostResulstsFn; /** Runs For `POST`, `PUT`, and `DELETE` */ crudMiddleware?: APIPathsParamsCrudMiddleware; method: "GET" | "POST" | "PUT" | "DELETE"; @@ -2931,6 +2932,17 @@ export type APIPathsParamsCrudMiddleware< targetId?: number | string; }) => Promise | undefined>; +export type APIPathsPostResulstsFn< + T extends { [k: string]: any } = { [k: string]: any }, + K extends string = string +> = (params: { + body?: APIPathsBody; + query?: DsqlCrudQueryObject; + table: K; + targetId?: number | string; + res?: APIResponseObject; +}) => Promise | undefined>; + export type APIPathsParamsAllowedTable = { table: string; allowedFields?: (string | RegExp)[]; diff --git a/package.json b/package.json index c7e744b..528064a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@moduletrace/datasquirel", - "version": "5.7.3", + "version": "5.7.4", "description": "Cloud-based SQL data management tool", "main": "dist/index.js", "bin": {