mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
fix: retrieve bills and bills payments list.
This commit is contained in:
@@ -7,6 +7,7 @@ import BillsService from 'services/Purchases/Bills';
|
||||
import BaseController from 'api/controllers/BaseController';
|
||||
import ItemsService from 'services/Items/ItemsService';
|
||||
import TenancyService from 'services/Tenancy/TenancyService';
|
||||
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||
import { ServiceError } from 'exceptions';
|
||||
|
||||
@Service()
|
||||
@@ -20,6 +21,9 @@ export default class BillsController extends BaseController {
|
||||
@Inject()
|
||||
tenancy: TenancyService;
|
||||
|
||||
@Inject()
|
||||
dynamicListService: DynamicListingService;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
@@ -28,7 +32,7 @@ export default class BillsController extends BaseController {
|
||||
|
||||
router.post(
|
||||
'/', [
|
||||
...this.billValidationSchema
|
||||
...this.billValidationSchema,
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.newBill.bind(this)),
|
||||
@@ -44,29 +48,25 @@ export default class BillsController extends BaseController {
|
||||
);
|
||||
router.get(
|
||||
'/:id', [
|
||||
...this.specificBillValidationSchema
|
||||
...this.specificBillValidationSchema,
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getBill.bind(this)),
|
||||
this.handleServiceError,
|
||||
);
|
||||
router.get(
|
||||
'/', [
|
||||
...this.billsListingValidationSchema,
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.billsList.bind(this)),
|
||||
this.handleServiceError,
|
||||
this.dynamicListService.handlerErrorsToResponse,
|
||||
);
|
||||
|
||||
// router.get(
|
||||
// '/:id',
|
||||
// [...this.specificBillValidationSchema],
|
||||
// this.validationResult,
|
||||
// asyncMiddleware(this.getBill.bind(this)),
|
||||
// this.handleServiceError,
|
||||
// );
|
||||
// router.get(
|
||||
// '/',
|
||||
// [...this.billsListingValidationSchema],
|
||||
// this.validationResult,
|
||||
// asyncMiddleware(this.listingBills.bind(this)),
|
||||
// this.handleServiceError,
|
||||
// );
|
||||
router.delete(
|
||||
'/:id',
|
||||
[...this.specificBillValidationSchema],
|
||||
'/:id', [
|
||||
...this.specificBillValidationSchema
|
||||
],
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.deleteBill.bind(this)),
|
||||
this.handleServiceError,
|
||||
@@ -221,8 +221,30 @@ export default class BillsController extends BaseController {
|
||||
* @param {Response} res -
|
||||
* @return {Response}
|
||||
*/
|
||||
async billsList(req: Request, res: Response) {
|
||||
|
||||
public async billsList(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req;
|
||||
const filter = {
|
||||
page: 1,
|
||||
pageSize: 12,
|
||||
filterRoles: [],
|
||||
sortOrder: 'asc',
|
||||
columnSortBy: 'created_at',
|
||||
...this.matchedQueryData(req),
|
||||
};
|
||||
if (filter.stringifiedFilterRoles) {
|
||||
filter.filterRoles = JSON.parse(filter.stringifiedFilterRoles);
|
||||
}
|
||||
try {
|
||||
const { bills, pagination, filterMeta } = await this.billsService.getBills(tenantId, filter);
|
||||
|
||||
return res.status(200).send({
|
||||
bills,
|
||||
pagination: this.transfromToResponse(pagination),
|
||||
filter_meta: this.transfromToResponse(filterMeta),
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,6 +6,7 @@ import asyncMiddleware from 'api/middleware/asyncMiddleware';
|
||||
import { ServiceError } from 'exceptions';
|
||||
import BaseController from 'api/controllers/BaseController';
|
||||
import BillPaymentsService from 'services/Purchases/BillPayments';
|
||||
import DynamicListingService from 'services/DynamicListing/DynamicListService';
|
||||
import AccountsService from 'services/Accounts/AccountsService';
|
||||
|
||||
/**
|
||||
@@ -20,6 +21,9 @@ export default class BillsPayments extends BaseController {
|
||||
@Inject()
|
||||
accountsService: AccountsService;
|
||||
|
||||
@Inject()
|
||||
dynamicListService: DynamicListingService;
|
||||
|
||||
/**
|
||||
* Router constructor.
|
||||
*/
|
||||
@@ -48,16 +52,19 @@ export default class BillsPayments extends BaseController {
|
||||
asyncMiddleware(this.deleteBillPayment.bind(this)),
|
||||
this.handleServiceError,
|
||||
);
|
||||
// router.get('/:id',
|
||||
// this.specificBillPaymentValidateSchema,
|
||||
// this.validationResult,
|
||||
// asyncMiddleware(this.getBillPayment.bind(this)),
|
||||
// );
|
||||
// router.get('/',
|
||||
// this.listingValidationSchema,
|
||||
// this.validationResult,
|
||||
// asyncMiddleware(this.getBillsPayments.bind(this))
|
||||
// );
|
||||
router.get('/:id',
|
||||
this.specificBillPaymentValidateSchema,
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getBillPayment.bind(this)),
|
||||
this.handleServiceError,
|
||||
);
|
||||
router.get('/',
|
||||
this.listingValidationSchema,
|
||||
this.validationResult,
|
||||
asyncMiddleware(this.getBillsPayments.bind(this)),
|
||||
this.handleServiceError,
|
||||
this.dynamicListService.handlerErrorsToResponse,
|
||||
);
|
||||
return router;
|
||||
}
|
||||
|
||||
@@ -183,10 +190,9 @@ export default class BillsPayments extends BaseController {
|
||||
const { tenantId } = req;
|
||||
const { id: billPaymentId } = req.params;
|
||||
|
||||
const billPayment = await this.billPaymentService
|
||||
.getBillPaymentWithMetadata(tenantId, billPaymentId);
|
||||
const billPayment = await this.billPaymentService.getBillPayment(tenantId, billPaymentId);
|
||||
|
||||
return res.status(200).send({ bill_payment: { ...billPayment } });
|
||||
return res.status(200).send({ bill_payment: billPayment });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -196,13 +202,19 @@ export default class BillsPayments extends BaseController {
|
||||
* @return {Response}
|
||||
*/
|
||||
async getBillsPayments(req: Request, res: Response, next: NextFunction) {
|
||||
const { tenantId } = req.params;
|
||||
const billPaymentsFilter = this.matchedQueryData(req);
|
||||
const { tenantId } = req;
|
||||
const billPaymentsFilter = {
|
||||
page: 1,
|
||||
pageSize: 12,
|
||||
filterRoles: [],
|
||||
sortOrder: 'asc',
|
||||
columnSortBy: 'created_at',
|
||||
...this.matchedQueryData(req),
|
||||
};
|
||||
|
||||
try {
|
||||
const { billPayments, pagination, filterMeta } = await this.billPaymentService
|
||||
.listBillPayments(tenantId, billPaymentsFilter);
|
||||
|
||||
const { billPayments, pagination, filterMeta } = await this.billPaymentService.listBillPayments(tenantId, billPaymentsFilter);
|
||||
|
||||
return res.status(200).send({
|
||||
bill_payments: billPayments,
|
||||
pagination: this.transfromToResponse(pagination),
|
||||
@@ -273,7 +285,6 @@ export default class BillsPayments extends BaseController {
|
||||
})
|
||||
}
|
||||
}
|
||||
console.log(error);
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user