Goal: Implementing the fetchApplicationById server action for internship that retrieves a single internship application by ID, with authentication validation, officer-only access control, backend API communication, and standardized error reporting.
Under app/actions/internship:
- Create the file fetchApplicationById.ts
- Import config and logger from lib
- Import token helpers from lib/token for role validation
- Import InternshipApplication and a suitable result type from lib/types/Internship
- Accept applicationId: string as the parameter
- Use cookie-based auth guard using token from next/headers
- Return { success: false, error: "Not authenticated" } when missing token
- Restrict access so only authenticated officers can fetch an application by ID
- Call backend GET /api/v1/internship/applications/:id using Config.API_URL + Config.routes.internship.applications + "/" + applicationId
- Send Authorization Bearer token header
- Parse backend response and map server messages into the error field
- Log failures with Logger.error("fetchApplicationById failed: ...") before returning error
- Return standardized result:
{ success: true, data: application } on success
{ success: false, error: "Failed to fetch application." } on failure
Create PR into Feat/ip-server-action NOT main
✅ Acceptance Criteria
- Type Definition: A result type exists in lib/types/Internship.ts for a single application fetch response.
- Auth Guard: The action must return { success: false, error: "Not authenticated" } if the user is not authenticated.
- Role Access: The action must deny access unless the authenticated user is an officer.
- API Call: The action must correctly call GET /app/api/v1/internship/applications/:id.
- Success Response: On success, the action returns { success: true, data: InternshipApplication }.
- Error Mapping: The function must correctly parse and return backend error messages to the UI when available.
- Exception Handling: Any uncaught errors (network, parsing) must be caught, logged with Logger.error(), and return { success: false, error: "Failed to fetch application." }.
Goal: Implementing the fetchApplicationById server action for internship that retrieves a single internship application by ID, with authentication validation, officer-only access control, backend API communication, and standardized error reporting.
Under app/actions/internship:
{ success: true, data: application } on success
{ success: false, error: "Failed to fetch application." } on failure
Create PR into Feat/ip-server-action NOT main
✅ Acceptance Criteria