feat: retrieve organization subscriptions list api.

feat: subscriptions reducers.
This commit is contained in:
Ahmed Bouhuolia
2020-10-13 21:46:32 +02:00
parent d71845a4c4
commit 8b97673100
23 changed files with 289 additions and 55 deletions

View File

@@ -1,12 +1,17 @@
import { Router } from 'express'
import { Container, Service } from 'typedi';
import { Router, Request, Response, NextFunction } from 'express'
import { Container, Service, Inject } from 'typedi';
import JWTAuth from 'api/middleware/jwtAuth';
import TenancyMiddleware from 'api/middleware/TenancyMiddleware';
import AttachCurrentTenantUser from 'api/middleware/AttachCurrentTenantUser';
import PaymentViaLicenseController from 'api/controllers/Subscription/PaymentViaLicense';
import SubscriptionService from 'services/Subscription/SubscriptionService';
import asyncMiddleware from 'api/middleware/asyncMiddleware';
@Service()
export default class SubscriptionController {
export default class SubscriptionController {
@Inject()
subscriptionService: SubscriptionService;
/**
* Router constructor.
*/
@@ -19,6 +24,26 @@ export default class SubscriptionController {
router.use('/license', Container.get(PaymentViaLicenseController).router());
router.get('/',
asyncMiddleware(this.getSubscriptions.bind(this))
);
return router;
}
/**
* Retrieve all subscriptions of the authenticated user's tenant.
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
*/
async getSubscriptions(req: Request, res: Response, next: NextFunction) {
const { tenantId } = req;
try {
const subscriptions = await this.subscriptionService.getSubscriptions(tenantId);
return res.status(200).send({ subscriptions });
} catch (error) {
next(error);
}
}
}