refactoring: media system.

This commit is contained in:
Ahmed Bouhuolia
2020-10-07 21:30:16 +02:00
parent 681fa0560e
commit 15dca0a7d2
14 changed files with 572 additions and 173 deletions

View File

@@ -7,6 +7,7 @@ import ExpensesService from "services/Expenses/ExpensesService";
import { IExpenseDTO } from 'interfaces';
import { ServiceError } from "exceptions";
import DynamicListingService from 'services/DynamicListing/DynamicListService';
import { takeWhile } from "lodash";
@Service()
export default class ExpensesController extends BaseController {
@@ -73,10 +74,19 @@ export default class ExpensesController extends BaseController {
'/', [
...this.expensesListSchema,
],
this.validationResult,
asyncMiddleware(this.getExpensesList.bind(this)),
this.dynamicListService.handlerErrorsToResponse,
this.catchServiceErrors,
);
router.get(
'/:id', [
this.expenseParamSchema,
],
this.validationResult,
asyncMiddleware(this.getExpense.bind(this)),
this.catchServiceErrors,
);
return router;
}
@@ -280,6 +290,24 @@ export default class ExpensesController extends BaseController {
}
}
/**
* Retrieve expense details.
* @param {Request} req
* @param {Response} res
* @param {NextFunction} next
*/
async getExpense(req: Request, res: Response, next: NextFunction) {
const { tenantId } = req;
const { id: expenseId } = req.params;
try {
const expense = await this.expensesService.getExpense(tenantId, expenseId);
return res.status(200).send({ expense });
} catch (error) {
next(error);
}
}
/**
* Transform service errors to api response errors.
* @param {Response} res