-
Notifications
You must be signed in to change notification settings - Fork 18
feat: add admin subscription plans endpoints #58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
codebestia
merged 11 commits into
ShadeProtocol:main
from
codeZe-us:admin_subscription_api
Aug 30, 2026
Merged
Changes from 9 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e8be536
feat(admin): add read and moderation endpoints over merchants
Damola09 14b2f55
feat(admin): add superadmin-only create-admin endpoint
dslegacy f0305e6
feat: add admin subscription plans endpoints
codeZe-us 2e5a5fc
Merge branch 'main' into admin_subscription_api
codebestia 68b0464
Merge pull request #56 from Damola09/feat/admin-merchant-endpoints
codebestia bb839ce
fix(admin): make create-admin atomic and tighten validation
dslegacy 27f3142
Merge pull request #57 from dslegacy/feat/create-admin-endpoint
codebestia 61614a9
feat: add admin subscription plans endpoints
codeZe-us 60e30c9
Merge branch 'admin_subscription_api' of https://github.com/codeZe-us…
codeZe-us b11d131
fix: fixes
codeZe-us 2bde458
done: done
codeZe-us File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| import { Request, Response } from 'express'; | ||
| import { | ||
| listSubscriptionPlans, | ||
| getSubscriptionPlan, | ||
| } from '../services/admin-subscription-plan.services.js'; | ||
| import { parseAdminSubscriptionPlanListQuery } from '../utils/admin-subscription-plan.validation.js'; | ||
| import { AppError } from '../utils/errors.js'; | ||
|
|
||
| export const listSubscriptionPlansController = async ( | ||
| req: Request, | ||
| res: Response, | ||
| ): Promise<void> => { | ||
| const { filters, pagination, sortBy, sortDir, errors } = parseAdminSubscriptionPlanListQuery( | ||
| req.query as Record<string, unknown>, | ||
| ); | ||
|
|
||
| if (Object.keys(errors).length > 0) { | ||
| res.status(400).json({ error: 'Validation failed', errors }); | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const result = await listSubscriptionPlans(filters, pagination, sortBy, sortDir); | ||
| res.status(200).json(result); | ||
| } catch (error) { | ||
| handleError(error, req, res); | ||
| } | ||
| }; | ||
|
|
||
| export const getSubscriptionPlanController = async (req: Request, res: Response): Promise<void> => { | ||
| try { | ||
| const plan = await getSubscriptionPlan(req.params.id as string); | ||
| res.status(200).json(plan); | ||
| } catch (error) { | ||
| handleError(error, req, res); | ||
| } | ||
| }; | ||
|
|
||
| const handleError = (error: unknown, req: Request, res: Response): void => { | ||
| if (error instanceof AppError) { | ||
| res.status(error.statusCode).json({ error: error.message }); | ||
| return; | ||
| } | ||
|
|
||
| console.error('Failed to process admin subscription plans request', { | ||
| path: req.path, | ||
| method: req.method, | ||
| error: error instanceof Error ? error.message : 'Unknown error', | ||
| }); | ||
| res.status(500).json({ error: 'Internal Server Error' }); | ||
| }; |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import { Router } from 'express'; | ||
| import { createAdminController } from '../../controllers/admin-auth.controllers.js'; | ||
| import { requireSuperAdmin } from '../../middlewares/admin.middleware.js'; | ||
|
|
||
| const router = Router(); | ||
|
|
||
| // Admin management is superadmin-only. authenticateAdmin is applied where this | ||
| // router is mounted (admin/index.ts); requireSuperAdmin chains after it. | ||
| router.post('/', requireSuperAdmin, createAdminController); | ||
|
|
||
| export default router; |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,24 @@ | ||
| import { Router } from 'express'; | ||
| import { blockMerchantController } from '../../controllers/admin-merchant.controllers.js'; | ||
| import { | ||
| blockMerchantController, | ||
| getMerchantAnalyticsController, | ||
| getMerchantController, | ||
| listMerchantInvoicesController, | ||
| listMerchantsController, | ||
| } from '../../controllers/admin-merchant.controllers.js'; | ||
| import { requireSuperAdmin } from '../../middlewares/admin.middleware.js'; | ||
|
|
||
| const router = Router(); | ||
|
|
||
| router.patch('/:id/block', blockMerchantController); | ||
| // Read-only dashboard data: any authenticated admin, no superadmin requirement. | ||
| // authenticateAdmin is applied where this router is mounted (admin/index.ts). | ||
| router.get('/', listMerchantsController); | ||
| router.get('/:id', getMerchantController); | ||
| router.get('/:id/invoices', listMerchantInvoicesController); | ||
| router.get('/:id/analytics', getMerchantAnalyticsController); | ||
|
|
||
| // Moderation: superadmin only. Unblocking is deliberately not exposed here — | ||
| // only blocking was in scope; see blockMerchant in merchant.services.ts. | ||
| router.post('/:id/block', requireSuperAdmin, blockMerchantController); | ||
|
|
||
| export default router; |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { Router } from 'express'; | ||
| import { | ||
| listSubscriptionPlansController, | ||
| getSubscriptionPlanController, | ||
| } from '../../controllers/admin-subscription-plan.controllers.js'; | ||
|
|
||
| const router = Router(); | ||
|
|
||
| router.get('/', listSubscriptionPlansController); | ||
| router.get('/:id', getSubscriptionPlanController); | ||
|
|
||
| export default router; |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.