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 { ISaleInvocieState } from '@/interfaces';
import HasTenancyService from '@/services/Tenancy/TenancyService';
@Service()
export class GetSaleInvoiceState {
@Inject()
private tenancy: HasTenancyService;
/**
*
* Retrieves the create/edit invoice state.
* @param {Number} saleInvoiceId -
* @return {Promise<ISaleInvoice>}
*/
public async getSaleInvoiceState(
tenantId: number
): Promise<ISaleInvocieState> {
const { PdfTemplate } = this.tenancy.models(tenantId);
const defaultPdfTemplate = await PdfTemplate.query()
.findOne({ resource: 'SaleInvoice' })
.modify('default');
return {
defaultTemplateId: 1,
defaultTemplateId: defaultPdfTemplate?.id,
};
}
}