hngprojects / hng_boilerplate_expressjs

75 stars 85 forks source link

[FEAT]: Deactivate Invitation Link - Backend #2

Closed SamixYasuke closed 3 months ago

SamixYasuke commented 3 months ago

Description

Create an API endpoint to handle the deactivation of invitation links. This endpoint will validate the invitation link and deactivate it to prevent any further use, ensuring the user deactivating the link has proper authorization.

Endpoint Feature

Acceptance Criteria

API Endpoint Implementation:

Data Validation and Sanitization:

Authorization:

Deactivating the Invitation Link:

Response:

Request Example

[PATCH] /api/v1/invite/deactivate

{
  "invitation_link": "string"
}

Successful Response:

{
  "message": "Invitation link has been deactivated",
  "status_code": 200
}

Error Response:

{
  "error":  "Invitation Not Found" ,
  "status_code": 404
}
{
  "error":  "Invitation Link wasn't provided" ,
  "status_code": 400
}
{
  "error":  "Invalid Invitation Link format" ,
  "status_code": 400
}
{
  "error": "User is not authorized to deactivate this invitation link" ,
  "status_code": 403
}
{
  "error": "Invitation link is already deactivated" ,
  "status_code": 403
}
{
  "error": "Invitation link is expired" ,
  "status_code": 400
}

Authentication and Authorization

Authentication Verify that the user is authenticated before allowing access to the endpoint. Example: Use middleware to check for a valid authentication token.

Authorization Ensure that only authorized users can deactivate the invitation link (i.e. the user that created it).

Purpose

Provides a backend service to handle the deactivation of invitation links, ensuring the link cannot be used again once deactivated and that only authorized users can perform this action.

Requirements

Expected Outcome

The API endpoint allows authorized users to deactivate invitation links via the provided link and ensures they cannot be used again.

Status Codes

Performance and Security

Documentation

Ensure that API documentation is updated to include information for the endpoint, request/response formats, error handling, and authentication requirements, swagger would be used for the documentation using OpenAPI 3.1.0 standard.

Testing

Dependencies and Impact

Dependencies:

Impact Analysis:

SamixYasuke commented 3 months ago

This ticket is referred from the main Boilerplate repo Issue #193