Merge pull request #696 from bigcapitalhq/fix-changing-pdf-template

fix: Changing the pdf template of the invoice
This commit is contained in:
Ahmed Bouhuolia
2024-10-07 09:51:17 +02:00
committed by GitHub

View File

@@ -1,7 +1,6 @@
import * as R from 'ramda';
import HasTenancyService from '../Tenancy/TenancyService';
import { Inject, Service } from 'typedi'; import { Inject, Service } from 'typedi';
import { isEmpty } from 'lodash'; import { isNil } from 'lodash';
import HasTenancyService from '../Tenancy/TenancyService';
@Service() @Service()
export class BrandingTemplateDTOTransformer { export class BrandingTemplateDTOTransformer {
@@ -22,11 +21,12 @@ export class BrandingTemplateDTOTransformer {
const { PdfTemplate } = this.tenancy.models(tenantId); const { PdfTemplate } = this.tenancy.models(tenantId);
const attributeName = 'pdfTemplateId'; const attributeName = 'pdfTemplateId';
const defaultTemplate = await PdfTemplate.query().findOne({ const defaultTemplate = await PdfTemplate.query()
resource, .modify('default')
default: true, .findOne({ resource });
});
if (!defaultTemplate || !isEmpty(object[attributeName])) { // If the default template is not found OR the given object has no defined template id.
if (!defaultTemplate || !isNil(object[attributeName])) {
return object; return object;
} }
return { return {