fix: accounts types caching.

This commit is contained in:
Ahmed Bouhuolia
2020-09-30 11:45:25 +02:00
parent 4e8c670968
commit 7d8b05ff66
6 changed files with 99 additions and 23 deletions

View File

@@ -1,10 +1,14 @@
import { Service } from 'typedi';
import { Request, Response, Router } from 'express';
import { Service, Inject } from 'typedi';
import { Request, Response, Router, NextFunction } from 'express';
import asyncMiddleware from 'api/middleware/asyncMiddleware';
import BaseController from 'api/controllers/BaseController';
import AccountsTypesService from 'services/Accounts/AccountsTypesServices';
@Service()
export default class AccountsTypesController extends BaseController{
@Inject()
accountsTypesService: AccountsTypesService;
/**
* Router constructor.
*/
@@ -12,20 +16,22 @@ export default class AccountsTypesController extends BaseController{
const router = Router();
router.get('/',
asyncMiddleware(this.getAccountTypesList));
asyncMiddleware(this.getAccountTypesList.bind(this))
);
return router;
}
/**
* Retrieve accounts types list.
*/
async getAccountTypesList(req: Request, res: Response) {
const { AccountType } = req.models;
const accountTypes = await AccountType.query();
async getAccountTypesList(req: Request, res: Response, next: NextFunction) {
const { tenantId, user } = req;
return res.status(200).send({
account_types: accountTypes,
});
try {
const accountTypes = await this.accountsTypesService.getAccountsTypes(tenantId);
return res.status(200).send({ account_types: accountTypes });
} catch (error) {
next(error);
}
}
};