feat(subscriptions): Add subscription/premium tier data model and API - #218
Merged
Akatenvictor merged 2 commits intoJul 29, 2026
Merged
Conversation
…loses AudioBitsStellar#100) Introduce an RBAC layer that authorizes admin actions against named permissions rather than roles directly: - Permission enum + ROLE_PERMISSIONS map (LISTENER/ARTIST have none, MODERATOR moderates content, ADMIN manages users/roles, SUPER_ADMIN holds every permission) - requirePermission(permission) middleware: 401 unauthenticated, 403 when the role lacks the capability - New MODERATOR and SUPER_ADMIN roles on UserRole - Per-route permission guards on admin routes (content moderation, search rebuild, jobs, role assignment) - UserService.assignRole + AdminController.assignRole + AssignRoleDTO for POST /admin/users/:id/role - Idempotent migration adding the role column - 16 tests across permission map, middleware, service, and controller Also removes pre-existing unused imports in User.ts and UserService.ts surfaced by lint-staged on the touched files. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…Closes AudioBitsStellar#99) - Create Subscription entity with userId, tier, status, startDate, endDate - Add subscription tiers: free, artist_pro, label - Implement SubscriptionService with subscription management logic - Add GET /api/users/me/subscription endpoint to view current subscription - Add POST /api/subscriptions endpoint to create/upgrade subscriptions - Add DELETE /api/subscriptions endpoint to cancel subscriptions - Create tier-based feature gating middleware (requireTier) - Add checkTierAccess utility function for conditional tier checks - Create database migration for Subscription entity with constraints - Add comprehensive tests for SubscriptionService (15 tests passing) - Add tests for subscription middleware (7 tests) Implements acceptance criteria: ✓ Subscription entity with userId, tier, status, startDate, endDate ✓ Tiers: free, artist_pro, label ✓ GET /api/users/me/subscription returns current subscription ✓ POST /api/subscriptions creates or upgrades subscription ✓ DELETE /api/subscriptions cancels subscription at period end ✓ Tier-based feature gating utility function ✓ Migration for Subscription entity with indexes and constraints ✓ 15 tests passing with comprehensive coverage
|
@dev-susa Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #99
Summary
This PR implements a subscription/premium tier system that enables the platform to offer enhanced features to paying users like higher upload limits and advanced analytics.
Changes
Core Subscription System
Subscriptionentity with fields: userId, tier, status, startDate, endDatefree,artist_pro,labelactive,cancelled,expiredService Layer
SubscriptionServicewith full subscription lifecycle managementgetUserSubscription- retrieves user's active subscription with expiration checkingcreateOrUpgradeSubscription- creates new subscriptions or upgrades existing onescancelSubscription- cancels subscription while preserving access until end datehasTierAccess- checks tier access for feature gatingAPI Endpoints
GET /api/users/me/subscription- returns current user's subscriptionPOST /api/subscriptions- creates or upgrades a subscriptionDELETE /api/subscriptions- cancels subscription at period endMiddleware & Utilities
requireTiermiddleware for tier-based route protectioncheckTierAccessutility function for conditional tier checks in controllersDatabase
1753100000000-AddSubscriptionEntity.tsTesting
Subscription Tiers
API Examples
Get Current Subscription
Create/Upgrade Subscription
Cancel Subscription
Using Tier Middleware
Testing Evidence
All subscription functionality has comprehensive test coverage:
Test Coverage:
Acceptance Criteria Met
Notes