Files
bigcapital/packages/server/src/modules/PaymentReceived/queries/GetPaymentReceived.service.ts
Ahmed Bouhuolia 3575d54efa fix: add attachment support for all transaction types
Fixed attachments not showing in edit forms for various transaction types by:

1. Adding @InjectAttachable() decorator to models:
   - SaleReceipt, SaleEstimate, CreditNote, PaymentReceived
   - Bill, BillPayment, VendorCredit
   - ManualJournal, Expense

2. Fixing transformers to include attachments in API responses:
   - SaleReceiptTransformer, PaymentReceivedTransformer

3. Registering missing event subscribers in Attachment.module.ts:
   - AttachmentsOnSaleReceipts, AttachmentsOnSaleEstimates

4. Fixing DocumentLink model relation mapping:
   - Changed Document.default to Document for proper module export

5. Fixing PaymentReceived model_ref consistency:
   - Changed from 'PaymentReceive' to 'PaymentReceived' to match class name

6. Adding missing withGraphFetched('attachments') to GetPaymentReceived.service.ts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-26 23:16:12 +02:00

47 lines
1.5 KiB
TypeScript

import { Inject, Injectable } from '@nestjs/common';
import { ERRORS } from '../constants';
import { PaymentReceiveTransfromer } from './PaymentReceivedTransformer';
import { PaymentReceived } from '../models/PaymentReceived';
import { TransformerInjectable } from '../../Transformer/TransformerInjectable.service';
import { ServiceError } from '../../Items/ServiceError';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class GetPaymentReceivedService {
constructor(
private readonly transformer: TransformerInjectable,
@Inject(PaymentReceived.name)
private readonly paymentReceiveModel: TenantModelProxy<
typeof PaymentReceived
>,
) {}
/**
* Retrieve payment receive details.
* @param {number} paymentReceiveId - Payment receive id.
* @return {Promise<IPaymentReceived>}
*/
public async getPaymentReceive(
paymentReceiveId: number,
): Promise<PaymentReceived> {
const paymentReceive = await this.paymentReceiveModel()
.query()
.withGraphFetched('customer')
.withGraphFetched('depositAccount')
.withGraphFetched('entries.invoice')
.withGraphFetched('transactions')
.withGraphFetched('branch')
.withGraphFetched('attachments')
.findById(paymentReceiveId);
if (!paymentReceive) {
throw new ServiceError(ERRORS.PAYMENT_RECEIVE_NOT_EXISTS);
}
return this.transformer.transform(
paymentReceive,
new PaymentReceiveTransfromer(),
);
}
}