Skip to content

Action: Fetch Application By ID #276

@Camillalalala

Description

@Camillalalala

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:

  1. Create the file fetchApplicationById.ts
  2. Import config and logger from lib
  3. Import token helpers from lib/token for role validation
  4. Import InternshipApplication and a suitable result type from lib/types/Internship
  5. Accept applicationId: string as the parameter
  6. Use cookie-based auth guard using token from next/headers
  7. Return { success: false, error: "Not authenticated" } when missing token
  8. Restrict access so only authenticated officers can fetch an application by ID
  9. Call backend GET /api/v1/internship/applications/:id using Config.API_URL + Config.routes.internship.applications + "/" + applicationId
  10. Send Authorization Bearer token header
  11. Parse backend response and map server messages into the error field
  12. Log failures with Logger.error("fetchApplicationById failed: ...") before returning error
  13. 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." }.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions