-
{translation?.select}
{isEmployeeTrue && }
{isOccupantTrue && }
diff --git a/WebServices/management-frontend/src/apicalls/application/endpoints.tsx b/WebServices/management-frontend/src/apicalls/application/endpoints.tsx
index 250aee5..7f87b8e 100644
--- a/WebServices/management-frontend/src/apicalls/application/endpoints.tsx
+++ b/WebServices/management-frontend/src/apicalls/application/endpoints.tsx
@@ -194,6 +194,7 @@ async function removeApplicationFromService(payload: RemoveApplicationFromServic
}
async function createApplication(payload: any) {
+ console.log("Creating application with payload:", payload);
try {
const response = await fetchDataWithToken(
applicationCreateEndpoint,
diff --git a/WebServices/management-frontend/src/app/api/utils/apiOperations.ts b/WebServices/management-frontend/src/app/api/utils/apiOperations.ts
index dcfcafa..69a90fb 100644
--- a/WebServices/management-frontend/src/app/api/utils/apiOperations.ts
+++ b/WebServices/management-frontend/src/app/api/utils/apiOperations.ts
@@ -63,12 +63,13 @@ export async function handleCreateOperation(
}
if (createFunction) {
+ console.log("Body:", body);
const result = await createFunction(body);
return createResponse(result);
}
return createResponse({
- id: Math.floor(Math.random() * 1000),
+ uuid: Math.floor(Math.random() * 1000),
...body,
});
}
@@ -136,9 +137,15 @@ export function createCreateHandler(
requiredFields: string[] = []
) {
console.log("Required fields:", requiredFields);
- return withErrorHandling((body: any) =>
- handleCreateOperation(body, createFunction, requiredFields)
- );
+ // This handler only takes the body parameter, not the request
+ return withErrorHandling((body: any) => {
+ // Ensure we're only passing the actual body data to the create function
+ if (body && typeof body === 'object' && body.body) {
+ console.log("Extracting body from request body");
+ return handleCreateOperation(body.body, createFunction, requiredFields);
+ }
+ return handleCreateOperation(body, createFunction, requiredFields);
+ });
}
/**
diff --git a/WebServices/management-frontend/src/app/api/utils/requestHandlers.ts b/WebServices/management-frontend/src/app/api/utils/requestHandlers.ts
index 77a5be3..ec8ecda 100644
--- a/WebServices/management-frontend/src/app/api/utils/requestHandlers.ts
+++ b/WebServices/management-frontend/src/app/api/utils/requestHandlers.ts
@@ -1,6 +1,6 @@
import { NextRequest } from "next/server";
import { errorResponse } from "./responseHandlers";
-import { ValidationResult, ApiHandler } from "./types";
+import { ValidationResult, ApiHandler, ApiHandlerBodyOnly, ApiHandlerWithRequest } from "./types";
/**
* Safely parse JSON request body with error handling
@@ -30,7 +30,15 @@ export function withErrorHandling(
return errorResponse("Invalid request body", 400);
}
- return await handler(request, body);
+ // Check handler parameter count to determine if it needs request object
+ // If handler has only 1 parameter, it's likely a create operation that only needs body
+ if (handler.length === 1) {
+ // Cast to the appropriate handler type
+ return await (handler as ApiHandlerBodyOnly)(body);
+ } else {
+ // Otherwise pass both request and body (for list, update, delete operations)
+ return await (handler as ApiHandlerWithRequest)(request, body);
+ }
} catch (error: any) {
return errorResponse(
error.message || "Internal Server Error",
diff --git a/WebServices/management-frontend/src/app/api/utils/types.ts b/WebServices/management-frontend/src/app/api/utils/types.ts
index 9f6a914..990bf90 100644
--- a/WebServices/management-frontend/src/app/api/utils/types.ts
+++ b/WebServices/management-frontend/src/app/api/utils/types.ts
@@ -90,9 +90,11 @@ export const collectPaginationFromApiResponse = (
};
/**
- * API handler function type
+ * API handler function types
*/
-export type ApiHandler = (request: NextRequest, body: any) => Promise
;
+export type ApiHandlerWithRequest = (request: NextRequest, body: any) => Promise;
+export type ApiHandlerBodyOnly = (body: any) => Promise;
+export type ApiHandler = ApiHandlerWithRequest | ApiHandlerBodyOnly;
/**
* List function type
diff --git a/WebServices/management-frontend/src/components/common/FormDisplay/CreateComponent.tsx b/WebServices/management-frontend/src/components/common/FormDisplay/CreateComponent.tsx
index 1a339bf..3e98437 100644
--- a/WebServices/management-frontend/src/components/common/FormDisplay/CreateComponent.tsx
+++ b/WebServices/management-frontend/src/components/common/FormDisplay/CreateComponent.tsx
@@ -103,7 +103,7 @@ export function CreateComponent({
const onSubmit: SubmitHandler> = async (data) => {
try {
if (apiUrl) {
- const createUrl = `${apiUrl}/create`;
+ const createUrl = `${apiUrl}`;
const response = await fetch(createUrl, {
method: 'POST',
headers: {
@@ -252,7 +252,7 @@ export function CreateComponent({
return null;
}
};
-
+
return (