refactor: tenant proxy providers

This commit is contained in:
Ahmed Bouhuolia
2025-02-15 23:52:12 +02:00
parent 36851d3209
commit 5c0bb52b59
302 changed files with 2396 additions and 1677 deletions

View File

@@ -13,6 +13,7 @@ import { events } from '@/common/events/events';
import { Customer } from '@/modules/Customers/models/Customer';
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
import { Inject, Injectable } from '@nestjs/common';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class CreatePaymentReceivedService {
@@ -24,10 +25,10 @@ export class CreatePaymentReceivedService {
private tenancyContext: TenancyContext,
@Inject(PaymentReceived.name)
private paymentReceived: typeof PaymentReceived,
private paymentReceived: TenantModelProxy<typeof PaymentReceived>,
@Inject(Customer.name)
private customer: typeof Customer,
private customer: TenantModelProxy<typeof Customer>,
) {}
/**
@@ -43,7 +44,7 @@ export class CreatePaymentReceivedService {
const tenant = await this.tenancyContext.getTenant(true);
// Validate customer existance.
const paymentCustomer = await this.customer
const paymentCustomer = await this.customer()
.query()
.findById(paymentReceiveDTO.customerId)
.throwIfNotFound();
@@ -85,7 +86,7 @@ export class CreatePaymentReceivedService {
} as IPaymentReceivedCreatingPayload);
// Inserts the payment receive transaction.
const paymentReceive = await this.paymentReceived
const paymentReceive = await this.paymentReceived()
.query(trx)
.insertGraphAndFetch({
...paymentReceiveObj,

View File

@@ -9,6 +9,7 @@ import {
IPaymentReceivedDeletingPayload,
IPaymentReceivedDeletedPayload,
} from '../types/PaymentReceived.types';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class DeletePaymentReceivedService {
@@ -23,10 +24,12 @@ export class DeletePaymentReceivedService {
private uow: UnitOfWork,
@Inject(PaymentReceived.name)
private paymentReceiveModel: typeof PaymentReceived,
private paymentReceiveModel: TenantModelProxy<typeof PaymentReceived>,
@Inject(PaymentReceivedEntry.name)
private paymentReceiveEntryModel: typeof PaymentReceivedEntry,
private paymentReceiveEntryModel: TenantModelProxy<
typeof PaymentReceivedEntry
>,
) {}
/**
@@ -44,7 +47,7 @@ export class DeletePaymentReceivedService {
*/
public async deletePaymentReceive(paymentReceiveId: number) {
// Retreive payment receive or throw not found service error.
const oldPaymentReceive = await this.paymentReceiveModel
const oldPaymentReceive = await this.paymentReceiveModel()
.query()
.withGraphFetched('entries')
.findById(paymentReceiveId)
@@ -59,13 +62,13 @@ export class DeletePaymentReceivedService {
} as IPaymentReceivedDeletingPayload);
// Deletes the payment receive associated entries.
await this.paymentReceiveEntryModel
await this.paymentReceiveEntryModel()
.query(trx)
.where('payment_receive_id', paymentReceiveId)
.delete();
// Deletes the payment receive transaction.
await this.paymentReceiveModel
await this.paymentReceiveModel()
.query(trx)
.findById(paymentReceiveId)
.delete();

View File

@@ -13,6 +13,7 @@ import { UnitOfWork } from '@/modules/Tenancy/TenancyDB/UnitOfWork.service';
import { events } from '@/common/events/events';
import { Customer } from '@/modules/Customers/models/Customer';
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class EditPaymentReceivedService {
@@ -24,10 +25,12 @@ export class EditPaymentReceivedService {
private readonly tenancyContext: TenancyContext,
@Inject(PaymentReceived.name)
private readonly paymentReceiveModel: typeof PaymentReceived,
private readonly paymentReceiveModel: TenantModelProxy<
typeof PaymentReceived
>,
@Inject(Customer.name)
private readonly customerModel: typeof Customer,
private readonly customerModel: TenantModelProxy<typeof Customer>,
) {}
/**
@@ -51,7 +54,7 @@ export class EditPaymentReceivedService {
const tenant = await this.tenancyContext.getTenant(true);
// Validate the payment receive existance.
const oldPaymentReceive = await this.paymentReceiveModel
const oldPaymentReceive = await this.paymentReceiveModel()
.query()
.withGraphFetched('entries')
.findById(paymentReceiveId)
@@ -61,7 +64,7 @@ export class EditPaymentReceivedService {
this.validators.validatePaymentExistance(oldPaymentReceive);
// Validate customer existance.
const customer = await this.customerModel
const customer = await this.customerModel()
.query()
.findById(paymentReceiveDTO.customerId)
.throwIfNotFound();
@@ -120,7 +123,7 @@ export class EditPaymentReceivedService {
} as IPaymentReceivedEditingPayload);
// Update the payment receive transaction.
const paymentReceive = await this.paymentReceiveModel
const paymentReceive = await this.paymentReceiveModel()
.query(trx)
.upsertGraphAndFetch({
id: paymentReceiveId,

View File

@@ -14,6 +14,7 @@ import { PaymentReceived } from '../models/PaymentReceived';
import { assocItemEntriesDefaultIndex } from '@/utils/associate-item-entries-index';
import { Customer } from '@/modules/Customers/models/Customer';
import { formatDateFields } from '@/utils/format-date-fields';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class PaymentReceiveDTOTransformer {
@@ -24,7 +25,9 @@ export class PaymentReceiveDTOTransformer {
private readonly brandingTemplatesTransformer: BrandingTemplateDTOTransformer,
@Inject(PaymentReceived.name)
private readonly paymentReceivedModel: typeof PaymentReceived,
private readonly paymentReceivedModel: TenantModelProxy<
typeof PaymentReceived
>,
) {}
/**
@@ -36,15 +39,14 @@ export class PaymentReceiveDTOTransformer {
public async transformPaymentReceiveDTOToModel(
customer: Customer,
paymentReceiveDTO: IPaymentReceivedCreateDTO | IPaymentReceivedEditDTO,
oldPaymentReceive?: PaymentReceived
oldPaymentReceive?: PaymentReceived,
): Promise<PaymentReceived> {
const amount =
paymentReceiveDTO.amount ??
sumBy(paymentReceiveDTO.entries, 'paymentAmount');
// Retreive the next invoice number.
const autoNextNumber =
this.increments.getNextPaymentReceiveNumber();
const autoNextNumber = this.increments.getNextPaymentReceiveNumber();
// Retrieve the next payment receive number.
const paymentReceiveNo =
@@ -56,7 +58,7 @@ export class PaymentReceiveDTOTransformer {
const entries = R.compose(
// Associate the default index to each item entry line.
assocItemEntriesDefaultIndex
assocItemEntriesDefaultIndex,
)(paymentReceiveDTO.entries);
const initialDTO = {
@@ -72,12 +74,12 @@ export class PaymentReceiveDTOTransformer {
const initialAsyncDTO = await composeAsync(
// Assigns the default branding template id to the invoice DTO.
this.brandingTemplatesTransformer.assocDefaultBrandingTemplate(
'SaleInvoice'
)
'SaleInvoice',
),
)(initialDTO);
return R.compose(
this.branchDTOTransform.transformDTO<PaymentReceived>
)(initialAsyncDTO) as PaymentReceived;
return R.compose(this.branchDTOTransform.transformDTO<PaymentReceived>)(
initialAsyncDTO,
) as PaymentReceived;
}
}

View File

@@ -3,12 +3,13 @@ import { Knex } from 'knex';
import { SaleInvoice } from '../../SaleInvoices/models/SaleInvoice';
import { IPaymentReceivedEntryDTO } from '../types/PaymentReceived.types';
import { entriesAmountDiff } from '@/utils/entries-amount-diff';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class PaymentReceivedInvoiceSync {
constructor(
@Inject(SaleInvoice.name)
private readonly saleInvoiceModel: typeof SaleInvoice,
private readonly saleInvoiceModel: TenantModelProxy<typeof SaleInvoice>,
) {}
/**
@@ -20,7 +21,7 @@ export class PaymentReceivedInvoiceSync {
public async saveChangeInvoicePaymentAmount(
newPaymentReceiveEntries: IPaymentReceivedEntryDTO[],
oldPaymentReceiveEntries?: IPaymentReceivedEntryDTO[],
trx?: Knex.Transaction
trx?: Knex.Transaction,
): Promise<void> {
const opers: Promise<void>[] = [];
@@ -28,16 +29,16 @@ export class PaymentReceivedInvoiceSync {
newPaymentReceiveEntries,
oldPaymentReceiveEntries,
'paymentAmount',
'invoiceId'
'invoiceId',
);
diffEntries.forEach((diffEntry: any) => {
if (diffEntry.paymentAmount === 0) {
return;
}
const oper = this.saleInvoiceModel.changePaymentAmount(
const oper = this.saleInvoiceModel().changePaymentAmount(
diffEntry.invoiceId,
diffEntry.paymentAmount,
trx
trx,
);
opers.push(oper);
});

View File

@@ -16,6 +16,7 @@ import { PaymentReceiveMailPresendEvent } from '../types/PaymentReceived.types';
import { SendInvoiceMailDTO } from '@/modules/SaleInvoices/SaleInvoice.types';
import { Mail } from '@/modules/Mail/Mail';
import { MailTransporter } from '@/modules/Mail/MailTransporter.service';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class SendPaymentReceiveMailNotification {
@@ -26,7 +27,9 @@ export class SendPaymentReceiveMailNotification {
private readonly mailTransport: MailTransporter,
@Inject(PaymentReceived.name)
private readonly paymentReceiveModel: typeof PaymentReceived,
private readonly paymentReceiveModel: TenantModelProxy<
typeof PaymentReceived
>,
) {}
/**
@@ -61,7 +64,7 @@ export class SendPaymentReceiveMailNotification {
public getMailOptions = async (
paymentId: number,
): Promise<PaymentReceiveMailOpts> => {
const paymentReceive = await this.paymentReceiveModel
const paymentReceive = await this.paymentReceiveModel()
.query()
.findById(paymentId)
.throwIfNotFound();

View File

@@ -11,21 +11,26 @@ import { Account } from '@/modules/Accounts/models/Account.model';
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
import { ServiceError } from '@/modules/Items/ServiceError';
import { ACCOUNT_TYPE } from '@/constants/accounts';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class PaymentReceivedValidators {
constructor(
@Inject(PaymentReceived.name)
private readonly paymentReceiveModel: typeof PaymentReceived,
private readonly paymentReceiveModel: TenantModelProxy<
typeof PaymentReceived
>,
@Inject(PaymentReceivedEntry.name)
private readonly paymentReceiveEntryModel: typeof PaymentReceivedEntry,
private readonly paymentReceiveEntryModel: TenantModelProxy<
typeof PaymentReceivedEntry
>,
@Inject(SaleInvoice.name)
private readonly saleInvoiceModel: typeof SaleInvoice,
private readonly saleInvoiceModel: TenantModelProxy<typeof SaleInvoice>,
@Inject(Account.name)
private readonly accountModel: typeof Account,
private readonly accountModel: TenantModelProxy<typeof Account>,
) {}
/**
@@ -45,9 +50,10 @@ export class PaymentReceivedValidators {
*/
public async validatePaymentReceiveNoExistance(
paymentReceiveNo: string,
notPaymentReceiveId?: number
notPaymentReceiveId?: number,
): Promise<void> {
const paymentReceive = await this.paymentReceiveModel.query()
const paymentReceive = await this.paymentReceiveModel()
.query()
.findOne('payment_receive_no', paymentReceiveNo)
.onBuild((builder) => {
if (notPaymentReceiveId) {
@@ -67,12 +73,13 @@ export class PaymentReceivedValidators {
*/
public async validateInvoicesIDsExistance(
customerId: number,
paymentReceiveEntries: { invoiceId: number }[]
paymentReceiveEntries: { invoiceId: number }[],
): Promise<SaleInvoice[]> {
const invoicesIds = paymentReceiveEntries.map(
(e: { invoiceId: number }) => e.invoiceId
(e: { invoiceId: number }) => e.invoiceId,
);
const storedInvoices = await this.saleInvoiceModel.query()
const storedInvoices = await this.saleInvoiceModel()
.query()
.whereIn('id', invoicesIds)
.where('customer_id', customerId);
@@ -84,7 +91,7 @@ export class PaymentReceivedValidators {
}
// Filters the not delivered invoices.
const notDeliveredInvoices = storedInvoices.filter(
(invoice) => !invoice.isDelivered
(invoice) => !invoice.isDelivered,
);
if (notDeliveredInvoices.length > 0) {
throw new ServiceError(ERRORS.INVOICES_NOT_DELIVERED_YET, null, {
@@ -101,13 +108,14 @@ export class PaymentReceivedValidators {
*/
public async validateInvoicesPaymentsAmount(
paymentReceiveEntries: IPaymentReceivedEntryDTO[],
oldPaymentEntries: PaymentReceivedEntry[] = []
oldPaymentEntries: PaymentReceivedEntry[] = [],
) {
const invoicesIds = paymentReceiveEntries.map(
(e: IPaymentReceivedEntryDTO) => e.invoiceId
(e: IPaymentReceivedEntryDTO) => e.invoiceId,
);
const storedInvoices = await this.saleInvoiceModel.query().whereIn('id', invoicesIds);
const storedInvoices = await this.saleInvoiceModel()
.query()
.whereIn('id', invoicesIds);
const storedInvoicesMap = new Map(
storedInvoices.map((invoice: SaleInvoice) => {
@@ -118,7 +126,7 @@ export class PaymentReceivedValidators {
invoice.id,
{ ...invoice, dueAmount: invoice.dueAmount + oldPaymentAmount },
];
})
}),
);
const hasWrongPaymentAmount: any[] = [];
@@ -130,7 +138,7 @@ export class PaymentReceivedValidators {
if (dueAmount < entry.paymentAmount) {
hasWrongPaymentAmount.push({ index, due_amount: dueAmount });
}
}
},
);
if (hasWrongPaymentAmount.length > 0) {
throw new ServiceError(ERRORS.INVALID_PAYMENT_AMOUNT);
@@ -154,16 +162,15 @@ export class PaymentReceivedValidators {
*/
public async validateEntriesIdsExistance(
paymentReceiveId: number,
paymentReceiveEntries: IPaymentReceivedEntryDTO[]
paymentReceiveEntries: IPaymentReceivedEntryDTO[],
) {
const entriesIds = paymentReceiveEntries
.filter((entry) => entry.id)
.map((entry) => entry.id);
const storedEntries = await this.paymentReceiveEntryModel.query().where(
'payment_receive_id',
paymentReceiveId
);
const storedEntries = await this.paymentReceiveEntryModel()
.query()
.where('payment_receive_id', paymentReceiveId);
const storedEntriesIds = storedEntries.map((entry: any) => entry.id);
const notFoundEntriesIds = difference(entriesIds, storedEntriesIds);
@@ -189,7 +196,7 @@ export class PaymentReceivedValidators {
*/
public validateCustomerNotModified(
paymentReceiveDTO: IPaymentReceivedEditDTO,
oldPaymentReceive: PaymentReceived
oldPaymentReceive: PaymentReceived,
) {
if (paymentReceiveDTO.customerId !== oldPaymentReceive.customerId) {
throw new ServiceError(ERRORS.PAYMENT_CUSTOMER_SHOULD_NOT_UPDATE);
@@ -199,15 +206,15 @@ export class PaymentReceivedValidators {
/**
* Validates the payment account currency code. The deposit account curreny
* should be equals the customer currency code or the base currency.
* @param {string} paymentAccountCurrency
* @param {string} customerCurrency
* @param {string} baseCurrency
* @param {string} paymentAccountCurrency
* @param {string} customerCurrency
* @param {string} baseCurrency
* @throws {ServiceError(ERRORS.PAYMENT_ACCOUNT_CURRENCY_INVALID)}
*/
public validatePaymentAccountCurrency = (
paymentAccountCurrency: string,
customerCurrency: string,
baseCurrency: string
baseCurrency: string,
) => {
if (
paymentAccountCurrency !== customerCurrency &&
@@ -222,9 +229,10 @@ export class PaymentReceivedValidators {
* @param {number} paymentReceiveId - Payment receive id.
*/
async getPaymentReceiveOrThrowError(
paymentReceiveId: number
paymentReceiveId: number,
): Promise<PaymentReceived> {
const paymentReceive = await this.paymentReceiveModel.query()
const paymentReceive = await this.paymentReceiveModel()
.query()
.withGraphFetched('entries')
.findById(paymentReceiveId);
@@ -240,9 +248,11 @@ export class PaymentReceivedValidators {
* @return {Promise<IAccount>}
*/
async getDepositAccountOrThrowError(
depositAccountId: number
depositAccountId: number,
): Promise<Account> {
const depositAccount = await this.accountModel.query().findById(depositAccountId);
const depositAccount = await this.accountModel()
.query()
.findById(depositAccountId);
if (!depositAccount) {
throw new ServiceError(ERRORS.DEPOSIT_ACCOUNT_NOT_FOUND);
@@ -264,13 +274,10 @@ export class PaymentReceivedValidators {
* Validate the given customer has no payments receives.
* @param {number} customerId - Customer id.
*/
public async validateCustomerHasNoPayments(
customerId: number
) {
const paymentReceives = await this.paymentReceiveModel.query().where(
'customer_id',
customerId
);
public async validateCustomerHasNoPayments(customerId: number) {
const paymentReceives = await this.paymentReceiveModel()
.query()
.where('customer_id', customerId);
if (paymentReceives.length > 0) {
throw new ServiceError(ERRORS.CUSTOMER_HAS_PAYMENT_RECEIVES);
}

View File

@@ -4,6 +4,7 @@ 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 {
@@ -11,7 +12,9 @@ export class GetPaymentReceivedService {
private readonly transformer: TransformerInjectable,
@Inject(PaymentReceived.name)
private readonly paymentReceiveModel: typeof PaymentReceived,
private readonly paymentReceiveModel: TenantModelProxy<
typeof PaymentReceived
>,
) {}
/**
@@ -20,9 +23,10 @@ export class GetPaymentReceivedService {
* @return {Promise<IPaymentReceived>}
*/
public async getPaymentReceive(
paymentReceiveId: number
paymentReceiveId: number,
): Promise<PaymentReceived> {
const paymentReceive = await this.paymentReceiveModel.query()
const paymentReceive = await this.paymentReceiveModel()
.query()
.withGraphFetched('customer')
.withGraphFetched('depositAccount')
.withGraphFetched('entries.invoice')
@@ -35,7 +39,7 @@ export class GetPaymentReceivedService {
}
return this.transformer.transform(
paymentReceive,
new PaymentReceiveTransfromer()
new PaymentReceiveTransfromer(),
);
}
}

View File

@@ -2,15 +2,16 @@ import { Inject, Injectable } from '@nestjs/common';
import { PaymentReceivedValidators } from '../commands/PaymentReceivedValidators.service';
import { SaleInvoice } from '../../SaleInvoices/models/SaleInvoice';
import { PaymentReceived } from '../models/PaymentReceived';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class GetPaymentReceivedInvoices {
constructor(
@Inject(PaymentReceived.name)
private paymentReceiveModel: typeof PaymentReceived,
private paymentReceiveModel: TenantModelProxy<typeof PaymentReceived>,
@Inject(SaleInvoice.name)
private saleInvoiceModel: typeof SaleInvoice,
private saleInvoiceModel: TenantModelProxy<typeof SaleInvoice>,
private validators: PaymentReceivedValidators,
) {}
@@ -21,7 +22,7 @@ export class GetPaymentReceivedInvoices {
* @return {Promise<ISaleInvoice>}
*/
public async getPaymentReceiveInvoices(paymentReceiveId: number) {
const paymentReceive = await this.paymentReceiveModel
const paymentReceive = await this.paymentReceiveModel()
.query()
.findById(paymentReceiveId)
.withGraphFetched('entries');
@@ -32,7 +33,7 @@ export class GetPaymentReceivedInvoices {
const paymentReceiveInvoicesIds = paymentReceive.entries.map(
(entry) => entry.invoiceId,
);
const saleInvoices = await this.saleInvoiceModel
const saleInvoices = await this.saleInvoiceModel()
.query()
.whereIn('id', paymentReceiveInvoicesIds);

View File

@@ -10,6 +10,7 @@ import { EventEmitter2 } from '@nestjs/event-emitter';
import { TemplateInjectable } from '@/modules/TemplateInjectable/TemplateInjectable.service';
import { PaymentReceivedPdfTemplateAttributes } from '../types/PaymentReceived.types';
import { events } from '@/common/events/events';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class GetPaymentReceivedPdfService {
@@ -21,10 +22,10 @@ export class GetPaymentReceivedPdfService {
private eventPublisher: EventEmitter2,
@Inject(PaymentReceived.name)
private paymentReceiveModel: typeof PaymentReceived,
private paymentReceiveModel: TenantModelProxy<typeof PaymentReceived>,
@Inject(PdfTemplateModel.name)
private pdfTemplateModel: typeof PdfTemplateModel,
private pdfTemplateModel: TenantModelProxy<typeof PdfTemplateModel>,
) {}
/**
@@ -66,7 +67,7 @@ export class GetPaymentReceivedPdfService {
private async getPaymentReceivedFilename(
paymentReceivedId: number,
): Promise<string> {
const payment = await this.paymentReceiveModel
const payment = await this.paymentReceiveModel()
.query()
.findById(paymentReceivedId);
@@ -87,7 +88,7 @@ export class GetPaymentReceivedPdfService {
const templateId =
paymentReceived?.pdfTemplateId ??
(
await this.pdfTemplateModel.query().findOne({
await this.pdfTemplateModel().query().findOne({
resource: 'PaymentReceive',
default: true,
})

View File

@@ -1,12 +1,13 @@
import { PdfTemplateModel } from '@/modules/PdfTemplate/models/PdfTemplate';
import { Inject, Injectable } from '@nestjs/common';
import { IPaymentReceivedState } from '../types/PaymentReceived.types';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class GetPaymentReceivedStateService {
constructor(
@Inject(PdfTemplateModel.name)
private pdfTemplateModel: typeof PdfTemplateModel,
private pdfTemplateModel: TenantModelProxy<typeof PdfTemplateModel>,
) {}
/**
@@ -14,7 +15,7 @@ export class GetPaymentReceivedStateService {
* @returns {Promise<IPaymentReceivedState>} - A promise resolving to the payment received state.
*/
public async getPaymentReceivedState(): Promise<IPaymentReceivedState> {
const defaultPdfTemplate = await this.pdfTemplateModel
const defaultPdfTemplate = await this.pdfTemplateModel()
.query()
.findOne({ resource: 'PaymentReceive' })
.modify('default');

View File

@@ -6,6 +6,7 @@ import { DynamicListService } from '@/modules/DynamicListing/DynamicList.service
import { PaymentReceived } from '../models/PaymentReceived';
import { IFilterMeta, IPaginationMeta } from '@/interfaces/Model';
import { IPaymentsReceivedFilter } from '../types/PaymentReceived.types';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class GetPaymentsReceivedService {
@@ -14,7 +15,9 @@ export class GetPaymentsReceivedService {
private readonly transformer: TransformerInjectable,
@Inject(PaymentReceived.name)
private readonly paymentReceivedModel: typeof PaymentReceived,
private readonly paymentReceivedModel: TenantModelProxy<
typeof PaymentReceived
>,
) {}
/**
@@ -34,7 +37,7 @@ export class GetPaymentsReceivedService {
PaymentReceived,
filter,
);
const { results, pagination } = await this.paymentReceivedModel
const { results, pagination } = await this.paymentReceivedModel()
.query()
.onBuild((builder) => {
builder.withGraphFetched('customer');

View File

@@ -5,6 +5,7 @@ import { ERRORS } from '../constants';
import { SaleInvoice } from '@/modules/SaleInvoices/models/SaleInvoice';
import { PaymentReceived } from '../models/PaymentReceived';
import { ServiceError } from '@/modules/Items/ServiceError';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
/**
* Payment receives edit/new pages service.
@@ -13,10 +14,10 @@ import { ServiceError } from '@/modules/Items/ServiceError';
export class PaymentsReceivedPagesService {
constructor(
@Inject(SaleInvoice.name)
private readonly saleInvoice: typeof SaleInvoice,
private readonly saleInvoice: TenantModelProxy<typeof SaleInvoice>,
@Inject(PaymentReceived.name)
private readonly paymentReceived: typeof PaymentReceived,
private readonly paymentReceived: TenantModelProxy<typeof PaymentReceived>,
) {}
/**
@@ -46,7 +47,7 @@ export class PaymentsReceivedPagesService {
*/
public async getNewPageEntries(tenantId: number, customerId: number) {
// Retrieve due invoices.
const entries = await this.saleInvoice
const entries = await this.saleInvoice()
.query()
.modify('delivered')
.modify('dueInvoices')
@@ -69,7 +70,7 @@ export class PaymentsReceivedPagesService {
entries: IPaymentReceivePageEntry[];
}> {
// Retrieve payment receive.
const paymentReceive = await this.paymentReceived
const paymentReceive = await this.paymentReceived()
.query()
.findById(paymentReceiveId)
.withGraphFetched('entries.invoice')
@@ -86,7 +87,7 @@ export class PaymentsReceivedPagesService {
index: entry.index,
}));
// Retrieves all receivable bills that associated to the payment receive transaction.
const restReceivableInvoices = await this.saleInvoice
const restReceivableInvoices = await this.saleInvoice()
.query()
.modify('delivered')
.modify('dueInvoices')