fix: validate payment made entries ids exists.

fix: retrieve payment made and receive details.
This commit is contained in:
Ahmed Bouhuolia
2020-11-04 00:23:58 +02:00
parent 083a2dfbc5
commit 1738a333c7
6 changed files with 132 additions and 38 deletions

View File

@@ -198,13 +198,16 @@ export default class BillsPayments extends BaseController {
const { id: billPaymentId } = req.params;
try {
const { billPayment, payableBills } = await this.billPaymentService.getBillPayment(tenantId, billPaymentId);
const {
billPayment,
payableBills,
paymentMadeBills,
} = await this.billPaymentService.getBillPayment(tenantId, billPaymentId);
return res.status(200).send({
bill_payment: {
...this.transfromToResponse({ ...billPayment }),
payable_bills: payableBills,
},
bill_payment: this.transfromToResponse({ ...billPayment }),
payable_bills: this.transfromToResponse([ ...payableBills ]),
payment_bills: this.transfromToResponse([ ...paymentMadeBills ]),
});
} catch (error) {
next(error);

View File

@@ -7,6 +7,7 @@ import asyncMiddleware from 'api/middleware/asyncMiddleware';
import PaymentReceiveService from 'services/Sales/PaymentsReceives';
import DynamicListingService from 'services/DynamicListing/DynamicListService';
import { ServiceError } from 'exceptions';
import HasItemEntries from 'services/Sales/HasItemsEntries';
/**
* Payments receives controller.
@@ -209,10 +210,19 @@ export default class PaymentReceivesController extends BaseController {
const { id: paymentReceiveId } = req.params;
try {
const paymentReceive = await this.paymentReceiveService.getPaymentReceive(
const {
paymentReceive,
receivableInvoices,
paymentReceiveInvoices,
} = await this.paymentReceiveService.getPaymentReceive(
tenantId, paymentReceiveId
);
return res.status(200).send({ paymentReceive });
return res.status(200).send({
payment_receive: this.transfromToResponse({ ...paymentReceive }),
receivable_invoices: this.transfromToResponse([ ...receivableInvoices ]),
payment_invoices: this.transfromToResponse([ ...paymentReceiveInvoices ]),
});
} catch (error) {
next(error);
}
@@ -314,7 +324,7 @@ export default class PaymentReceivesController extends BaseController {
errors: [{ type: 'INVOICES_IDS_NOT_FOUND', code: 300 }],
});
}
if (error.errorType === 'ENTRIES_IDS_NOT_FOUND') {
if (error.errorType === 'ENTRIES_IDS_NOT_EXISTS') {
return res.boom.badRequest(null, {
errors: [{ type: 'ENTRIES_IDS_NOT_FOUND', code: 300 }],
});
@@ -324,6 +334,12 @@ export default class PaymentReceivesController extends BaseController {
errors: [{ type: 'CUSTOMER_NOT_FOUND', code: 300 }],
});
}
if (error.errorType === 'INVALID_PAYMENT_AMOUNT') {
return res.boom.badRequest(null, {
errors: [{ type: 'INVALID_PAYMENT_AMOUNT', code: 1000 }],
});
}
console.log(error.errorType);
}
next(error);
}

View File

@@ -84,7 +84,7 @@ export default class SaleInvoicesController extends BaseController{
check('customer_id').exists().isNumeric().toInt(),
check('invoice_date').exists().isISO8601(),
check('due_date').exists().isISO8601(),
check('invoice_no').exists().trim().escape(),
check('invoice_no').optional().trim().escape(),
check('reference_no').optional().trim().escape(),
check('status').exists().trim().escape(),