Skip to content

Implement Newsletter Subscription Endpoint (Get Notified)Β #442

@yusuftomilola

Description

@yusuftomilola

We need to implement a newsletter subscription endpoint that allows users to subscribe to our mailing list and receive notifications. The backend implementation must align with the existing frontend newsletter component's type definitions and API contract.

🎯 Objective

Create a production-ready newsletter subscription endpoint:

  • POST /newsletter/subscribe - Subscribe users to the newsletter

πŸ“‚ Context

The frontend newsletter component has already been implemented. Please review:

  • Newsletter Component: /frontend/components/ui/newsletter
  • Type definitions: Check for newsletter-related types/interfaces
  • Form component: Review the newsletter form structure
  • Validation schemas: Check frontend validation rules
  • API service files: Look for expected request/response structures

βœ… Acceptance Criteria

1. Newsletter Subscription Endpoint (POST /newsletter/subscribe)

  • Accept email address from user
  • Validate email format
  • Check for duplicate subscriptions (prevent re-subscribing)
  • Store subscriber information in database
  • Add subscription timestamp
  • Generate unique subscription ID/token
  • Return appropriate success/error responses
  • Match frontend type expectations exactly

2. Data Validation

  • Email format validation
  • Sanitize input to prevent XSS/injection attacks
  • Handle empty/null values gracefully
  • Validate against disposable email addresses (optional but recommended)
  • Rate limiting to prevent spam (bonus points!)

3. Database Schema

  • Create Newsletter or Subscriber entity
  • Include fields: email, subscribedAt, isActive, unsubscribeToken
  • Add unique constraint on email field
  • Include soft delete capability (for unsubscribes)
  • Add indexes for performance

4. Optional Features (Bonus Points!)

  • Send confirmation email to subscriber
  • Double opt-in mechanism (send verification link)
  • Unsubscribe endpoint (POST /newsletter/unsubscribe)
  • GDPR compliance fields (consent timestamp, IP address)
  • Email service integration (SendGrid, Mailchimp, etc.)

5. Testing & Documentation

  • Server runs without errors
  • Endpoint tested with Postman/Thunder Client/similar tool
  • Include screenshots of successful API calls in PR
  • Test duplicate subscription handling
  • Test invalid email formats
  • Add error handling for all scenarios
  • Write basic unit tests (bonus points!)
  • Update API documentation/Swagger if applicable

πŸ› οΈ Technical Requirements

Required Technologies

  • Framework: NestJS
  • Database: PostgreSQL with TypeORM
  • Validation: class-validator & class-transformer
  • Email: nodemailer,

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions