{"id":22150736,"url":"https://github.com/d-d-roshan/user-notification-preferences-api-","last_synced_at":"2025-03-24T13:12:17.697Z","repository":{"id":263543082,"uuid":"890431480","full_name":"D-D-Roshan/User-Notification-Preferences-API-","owner":"D-D-Roshan","description":"User notification preference","archived":false,"fork":false,"pushed_at":"2024-11-20T12:42:02.000Z","size":321,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-29T18:12:33.069Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://user-notification-preferences-api-nine.vercel.app/","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/D-D-Roshan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-11-18T14:58:13.000Z","updated_at":"2024-11-20T12:42:06.000Z","dependencies_parsed_at":"2024-11-19T05:58:28.453Z","dependency_job_id":null,"html_url":"https://github.com/D-D-Roshan/User-Notification-Preferences-API-","commit_stats":null,"previous_names":["d-d-roshan/user-notification-preferences-api-"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/D-D-Roshan%2FUser-Notification-Preferences-API-","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/D-D-Roshan%2FUser-Notification-Preferences-API-/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/D-D-Roshan%2FUser-Notification-Preferences-API-/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/D-D-Roshan%2FUser-Notification-Preferences-API-/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/D-D-Roshan","download_url":"https://codeload.github.com/D-D-Roshan/User-Notification-Preferences-API-/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245276192,"owners_count":20588894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-02T00:20:51.176Z","updated_at":"2025-03-24T13:12:17.674Z","avatar_url":"https://github.com/D-D-Roshan.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# User Notification Preferences API\n\nThis API manages user notification preferences and handles notification delivery. It provides functionality for managing preferences for different types of notifications and channels, simulating notification sending, and tracking notification statuses.\n\n## API Features\n- **User Preferences Management**: CRUD operations for user preferences.\n- **Notification Management**: Simulate sending notifications and track their status.\n- **Basic Rate Limiting**: Prevent API abuse by limiting the number of requests.\n- **Request Logging**: Logs request details for debugging and monitoring.\n- **Statistics Tracking**: Provides basic stats on notifications sent.\n\n## Tech Stack\n- **NestJS**: Framework for building the API.\n- **TypeScript**: For type safety and better development experience.\n- **MongoDB with Mongoose**: To store user preferences and notification logs.\n- **Jest**: Testing framework for unit and integration tests.\n- **Class Validator**: For validating request bodies.\n- **Serverless Deployment**: Deployed to [Vercel](https://vercel.com) or [AWS Lambda](https://aws.amazon.com/lambda/).\n\n## Core Models\n### `UserPreference`\n```typescript\ninterface UserPreference {\n  userId: string;\n  email: string;\n  preferences: {\n    marketing: boolean;\n    newsletter: boolean;\n    updates: boolean;\n    frequency: 'daily' | 'weekly' | 'monthly' | 'never';\n    channels: {\n      email: boolean;\n      sms: boolean;\n      push: boolean;\n    };\n  };\n  timezone: string;\n  lastUpdated: Date;\n  createdAt: Date;\n}\n```\n\n### `NotificationLog`\n```typescript\ninterface NotificationLog {\n  userId: string;\n  type: 'marketing' | 'newsletter' | 'updates';\n  channel: 'email' | 'sms' | 'push';\n  status: 'pending' | 'sent' | 'failed';\n  sentAt?: Date;\n  failureReason?: string;\n  metadata: Record\u003cstring, any\u003e;\n}\n```\n\n## API Endpoints\n\n### User Preferences\n\n- **POST /api/preferences**\n  - Create user preferences.\n  - **Request Body**:\n    ```json\n    {\n      \"userId\": \"user123\",\n      \"email\": \"user@example.com\",\n      \"preferences\": {\n        \"marketing\": true,\n        \"newsletter\": false,\n        \"updates\": true,\n        \"frequency\": \"weekly\",\n        \"channels\": {\n          \"email\": true,\n          \"sms\": false,\n          \"push\": true\n        }\n      },\n      \"timezone\": \"America/New_York\"\n    }\n    ```\n  \n- **GET /api/preferences/:userId**\n  - Retrieve user preferences by `userId`.\n\n- **PATCH /api/preferences/:userId**\n  - Update user preferences by `userId`.\n  \n- **DELETE /api/preferences/:userId**\n  - Delete user preferences by `userId`.\n\n### Notification Management\n\n- **POST /api/notifications/send**\n  - Simulate sending a notification.\n  - **Request Body**:\n    ```json\n    {\n      \"userId\": \"user123\",\n      \"type\": \"marketing\",\n      \"channel\": \"email\",\n      \"content\": {\n        \"subject\": \"Special Offer\",\n        \"body\": \"Check out our latest deals!\"\n      }\n    }\n    ```\n\n- **GET /api/notifications/:userId/logs**\n  - Get notification logs for a user by `userId`.\n\n- **GET /api/notifications/stats**\n  - Get basic statistics on notifications sent.\n\n## Technical Requirements\n- **Data Models**: `UserPreference` and `NotificationLog`.\n- **Validation**: \n  - Valid email format.\n  - Valid timezone string.\n  - Enum validation for `frequency` and `status`.\n- **Rate Limiting**: Prevent abuse of the API.\n- **Error Handling**: Proper error messages and status codes.\n- **Unit \u0026 Integration Testing**: Test service layer, validation, API endpoints, and database operations.\n\n## Setup Instructions\n\n### Prerequisites\n\n- Node.js (v16 or higher)\n- MongoDB instance (can use MongoDB Atlas for cloud database)\n\n### Installation\n\n1. Clone the repository:\n   ```bash\n   git clone https://github.com/D-D-Roshan/User-Notification-Preferences-API-.git\n   cd your-repository\n   ```\n\n2. Install dependencies:\n   ```bash\n   npm install\n   ```\n\n3. Set up environment variables:\n   Create a `.env` file in the root directory with the following content:\n   ```env\n   MONGODB_URI=mongodb://localhost:27017/notification-preferences\n   \n   ```\n\n4. Run the application locally:\n   ```bash\n   npm run start:dev\n   ```\n\n   The API will be available at `http://localhost:3000`.\n\n### Deployment\n\nThis API is designed to be deployed to Vercel or AWS Lambda.\n\n#### Vercel Deployment\n\n1. Push the code to your GitHub repository.\n2. Create a new project on [Vercel](https://vercel.com).\n3. Link your repository and deploy.\n4. Set up environment variables in Vercel’s dashboard.\n\n#### AWS Lambda Deployment\n\n1. Use the [serverless framework](https://www.serverless.com/) to deploy:\n   - Install serverless framework globally:\n     ```bash\n     npm install -g serverless\n     ```\n   - Configure `serverless.yml` to deploy the app.\n   - Deploy using:\n     ```bash\n     serverless deploy\n     ```\n\n## API Documentation\n\n- **OpenAPI/Swagger**: Swagger documentation will be available at `http://localhost:3000/api-docs` when running locally. On deployment, it will be available via the same URL pattern.\n\n## Testing\n\n1. Run unit tests:\n   ```bash\n   npm run test\n   ```\n\n2. Run integration tests:\n   ```bash\n   npm run test:e2e\n   ```\n\n## Example Requests and Responses\n\n### Create User Preferences\n\n**Request**:\n```bash\nPOST /api/preferences\n```\n**Body**:\n```json\n{\n  \"userId\": \"user123\",\n  \"email\": \"user@example.com\",\n  \"preferences\": {\n    \"marketing\": true,\n    \"newsletter\": false,\n    \"updates\": true,\n    \"frequency\": \"weekly\",\n    \"channels\": {\n      \"email\": true,\n      \"sms\": false,\n      \"push\": true\n    }\n  },\n  \"timezone\": \"America/New_York\"\n}\n```\n\n**Response**:\n```json\n{\n  \"message\": \"User preferences created successfully\"\n}\n```\n\n### Send Notification\n\n**Request**:\n```bash\nPOST /api/notifications/send\n```\n**Body**:\n```json\n{\n  \"userId\": \"user123\",\n  \"type\": \"marketing\",\n  \"channel\": \"email\",\n  \"content\": {\n    \"subject\": \"Special Offer\",\n    \"body\": \"Check out our latest deals!\"\n  }\n}\n```\n\n**Response**:\n```json\n{\n  \"message\": \"Notification sent successfully\"\n}\n```\n\n## Environment Variables\n\n- `MONGODB_URI`: MongoDB connection URI.\n\n\n## Submission\n\nPlease provide the following:\n- GitHub repository link\n- Deployed API URL\n- Example requests and responses\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd-d-roshan%2Fuser-notification-preferences-api-","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fd-d-roshan%2Fuser-notification-preferences-api-","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fd-d-roshan%2Fuser-notification-preferences-api-/lists"}