mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: redesign accounts types.
This commit is contained in:
@@ -5,7 +5,7 @@ import BaseController from 'api/controllers/BaseController';
|
||||
import AccountsTypesService from 'services/Accounts/AccountsTypesServices';
|
||||
|
||||
@Service()
|
||||
export default class AccountsTypesController extends BaseController{
|
||||
export default class AccountsTypesController extends BaseController {
|
||||
@Inject()
|
||||
accountsTypesService: AccountsTypesService;
|
||||
|
||||
@@ -15,23 +15,26 @@ export default class AccountsTypesController extends BaseController{
|
||||
router() {
|
||||
const router = Router();
|
||||
|
||||
router.get('/',
|
||||
asyncMiddleware(this.getAccountTypesList.bind(this))
|
||||
);
|
||||
router.get('/', asyncMiddleware(this.getAccountTypesList.bind(this)));
|
||||
|
||||
return router;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve accounts types list.
|
||||
* @param {Request} req - Request.
|
||||
* @param {Response} res - Response.
|
||||
* @return {Response}
|
||||
*/
|
||||
async getAccountTypesList(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId, user } = req;
|
||||
|
||||
getAccountTypesList(req: Request, res: Response, next: NextFunction) {
|
||||
try {
|
||||
const accountTypes = await this.accountsTypesService.getAccountsTypes(tenantId);
|
||||
return res.status(200).send({ account_types: accountTypes });
|
||||
const accountTypes = this.accountsTypesService.getAccountsTypes();
|
||||
|
||||
return res.status(200).send({
|
||||
account_types: this.transfromToResponse(accountTypes, ['label'], req),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -109,10 +109,11 @@ export default class AccountsController extends BaseController {
|
||||
.isLength({ min: 3, max: 6 })
|
||||
.trim()
|
||||
.escape(),
|
||||
check('account_type_id')
|
||||
check('account_type')
|
||||
.exists()
|
||||
.isInt({ min: 0, max: DATATYPES_LENGTH.INT_10 })
|
||||
.toInt(),
|
||||
.isLength({ min: 3, max: DATATYPES_LENGTH.STRING })
|
||||
.trim()
|
||||
.escape(),
|
||||
check('description')
|
||||
.optional({ nullable: true })
|
||||
.isLength({ max: DATATYPES_LENGTH.TEXT })
|
||||
@@ -341,6 +342,7 @@ export default class AccountsController extends BaseController {
|
||||
* Retrieve accounts datatable list.
|
||||
* @param {Request} req
|
||||
* @param {Response} res
|
||||
* @param {Response}
|
||||
*/
|
||||
async getAccountsList(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
@@ -360,7 +362,7 @@ export default class AccountsController extends BaseController {
|
||||
} = await this.accountsService.getAccountsList(tenantId, filter);
|
||||
|
||||
return res.status(200).send({
|
||||
accounts,
|
||||
accounts: this.transfromToResponse(accounts, 'accountTypeLabel', req),
|
||||
filter_meta: this.transfromToResponse(filterMeta),
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Response, Request, NextFunction } from 'express';
|
||||
import { matchedData, validationResult } from "express-validator";
|
||||
import { camelCase, snakeCase, omit } from "lodash";
|
||||
import { camelCase, snakeCase, omit, set, get } from "lodash";
|
||||
import { mapKeysDeep } from 'utils'
|
||||
import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||
|
||||
@@ -61,8 +61,18 @@ export default class BaseController {
|
||||
* Transform the given data to response.
|
||||
* @param {any} data
|
||||
*/
|
||||
transfromToResponse(data: any) {
|
||||
return mapKeysDeep(data, (v, k) => snakeCase(k));
|
||||
transfromToResponse(data: any, translatable?: string | string[], req?: Request) {
|
||||
const response = mapKeysDeep(data, (v, k) => snakeCase(k));
|
||||
|
||||
if (translatable) {
|
||||
const translatables = Array.isArray(translatable) ? translatable : [translatable];
|
||||
|
||||
translatables.forEach((path) => {
|
||||
const value = get(response, path);
|
||||
set(response, path, req.__(value));
|
||||
});
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
asyncMiddleware(callback) {
|
||||
|
||||
@@ -334,10 +334,10 @@ export default class PaymentReceivesController extends BaseController {
|
||||
errors: [{ type: 'PAYMENT_RECEIVE_NOT_EXISTS', code: 300 }],
|
||||
});
|
||||
}
|
||||
if (error.errorType === 'DEPOSIT_ACCOUNT_NOT_CURRENT_ASSET_TYPE') {
|
||||
if (error.errorType === 'DEPOSIT_ACCOUNT_INVALID_TYPE') {
|
||||
return res.boom.badRequest(null, {
|
||||
errors: [
|
||||
{ type: 'DEPOSIT_ACCOUNT_NOT_CURRENT_ASSET_TYPE', code: 300 },
|
||||
{ type: 'DEPOSIT_ACCOUNT_INVALID_TYPE', code: 300 },
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user