feat: Assign default pdf template automatically

This commit is contained in:
Ahmed Bouhuolia
2024-10-03 16:36:44 +02:00
parent b23112bc92
commit 3c7e22be43
21 changed files with 332 additions and 38 deletions

View File

@@ -1,18 +1,28 @@
import { Service } from 'typedi';
import { Inject, Service } from 'typedi';
import { IPaymentReceivedState } from '@/interfaces';
import HasTenancyService from '@/services/Tenancy/TenancyService';
@Service()
export class GetPaymentReceivedState {
@Inject()
private tenancy: HasTenancyService;
/**
* Retrieves the current state of the payment received.
* Retrieves the create/edit initial state of the payment received.
* @param {number} tenantId - The ID of the tenant.
* @returns {Promise<IPaymentReceivedState>} - A promise resolving to the payment received state.
*/
public async getPaymentReceivedState(
tenantId: number
): Promise<IPaymentReceivedState> {
const { PdfTemplate } = this.tenancy.models(tenantId);
const defaultPdfTemplate = await PdfTemplate.query()
.findOne({ resource: 'PaymentReceive' })
.modify('default');
return {
defaultTemplateId: 1,
defaultTemplateId: defaultPdfTemplate?.id,
};
}
}