Merge pull request #352 from bigcapitalhq/big-138-revert-the-paid-amount-to-bill-transaction-after-editing

fix(server): Revert the paid amount to bill transaction after editing bill payment amount
This commit is contained in:
Ahmed Bouhuolia
2024-02-05 18:52:09 +02:00
committed by GitHub
6 changed files with 15 additions and 44 deletions

View File

@@ -10,7 +10,6 @@ import {
import TenancyService from '@/services/Tenancy/TenancyService';
import { ServiceError } from '@/exceptions';
import { ACCOUNT_TYPE } from '@/data/AccountTypes';
import { BillPayment } from '@/models';
import { ERRORS } from './constants';
@Service()
@@ -18,19 +17,6 @@ export class BillPaymentValidators {
@Inject()
private tenancy: TenancyService;
/**
* Validates the payment existance.
* @param {BillPayment | undefined | null} payment
* @throws {ServiceError(ERRORS.PAYMENT_MADE_NOT_FOUND)}
*/
public async validateBillPaymentExistance(
payment: BillPayment | undefined | null
) {
if (!payment) {
throw new ServiceError(ERRORS.PAYMENT_MADE_NOT_FOUND);
}
}
/**
* Validates the bill payment existance.
* @param {Request} req

View File

@@ -1,6 +1,5 @@
import { Knex } from 'knex';
import UnitOfWork from '@/services/UnitOfWork';
import { BillPaymentValidators } from './BillPaymentValidators';
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { Inject, Service } from 'typedi';
@@ -21,9 +20,6 @@ export class DeleteBillPayment {
@Inject()
private uow: UnitOfWork;
@Inject()
private validators: BillPaymentValidators;
/**
* Deletes the bill payment and associated transactions.
* @param {number} tenantId - Tenant id.
@@ -36,10 +32,8 @@ export class DeleteBillPayment {
// Retrieve the bill payment or throw not found service error.
const oldBillPayment = await BillPayment.query()
.withGraphFetched('entries')
.findById(billPaymentId);
// Validates the bill payment existance.
this.validators.validateBillPaymentExistance(oldBillPayment);
.findById(billPaymentId)
.throwIfNotFound();
// Deletes the bill transactions with associated transactions under
// unit-of-work envirement.

View File

@@ -57,12 +57,12 @@ export class EditBillPayment {
const tenantMeta = await TenantMetadata.query().findOne({ tenantId });
const oldBillPayment = await BillPayment.query().findById(billPaymentId);
const oldBillPayment = await BillPayment.query()
.findById(billPaymentId)
.withGraphFetched('entries')
.throwIfNotFound();
// Validates the bill payment existance.
this.validators.validateBillPaymentExistance(oldBillPayment);
//
// Retrieves the bill payment vendor or throw not found error.
const vendor = await Contact.query()
.modify('vendor')
.findById(billPaymentDTO.vendorId)
@@ -126,7 +126,7 @@ export class EditBillPayment {
trx,
} as IBillPaymentEditingPayload);
// Deletes the bill payment transaction graph from the storage.
// Edits the bill payment transaction graph on the storage.
const billPayment = await BillPayment.query(trx).upsertGraphAndFetch({
id: billPaymentId,
...billPaymentObj,

View File

@@ -1,12 +1,8 @@
import { IBillPayment } from '@/interfaces';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { Inject, Service } from 'typedi';
import { ERRORS } from './constants';
import { ServiceError } from '@/exceptions';
import { BillPaymentTransformer } from './BillPaymentTransformer';
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
import { BillsValidators } from '../Bills/BillsValidators';
import { BillPaymentValidators } from './BillPaymentValidators';
@Service()
export class GetBillPayment {
@@ -16,9 +12,6 @@ export class GetBillPayment {
@Inject()
private transformer: TransformerInjectable;
@Inject()
private validators: BillPaymentValidators;
/**
* Retrieve bill payment.
* @param {number} tenantId
@@ -37,10 +30,8 @@ export class GetBillPayment {
.withGraphFetched('paymentAccount')
.withGraphFetched('transactions')
.withGraphFetched('branch')
.findById(billPyamentId);
// Validates the bill payment existance.
this.validators.validateBillPaymentExistance(billPayment);
.findById(billPyamentId)
.throwIfNotFound();
return this.transformer.transform(
tenantId,

View File

@@ -18,10 +18,9 @@ export class GetPaymentBills {
public async getPaymentBills(tenantId: number, billPaymentId: number) {
const { Bill, BillPayment } = this.tenancy.models(tenantId);
const billPayment = await BillPayment.query().findById(billPaymentId);
// Validates the bill payment existance.
this.validators.validateBillPaymentExistance(billPayment);
const billPayment = await BillPayment.query()
.findById(billPaymentId)
.throwIfNotFound();
const paymentBillsIds = billPayment.entries.map((entry) => entry.id);

View File

@@ -61,7 +61,8 @@ export class EditPaymentReceive {
// Validate the payment receive existance.
const oldPaymentReceive = await PaymentReceive.query()
.withGraphFetched('entries')
.findById(paymentReceiveId);
.findById(paymentReceiveId)
.throwIfNotFound();
// Validates the payment existance.
this.validators.validatePaymentExistance(oldPaymentReceive);