mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 05:10:31 +00:00
feat: hook up branding templates to invoices
This commit is contained in:
@@ -33,6 +33,14 @@ export class AssignPdfTemplateDefault {
|
||||
return this.uow.withTransaction(
|
||||
tenantId,
|
||||
async (trx?: Knex.Transaction) => {
|
||||
// Triggers `onPdfTemplateAssigningDefault` event.
|
||||
await this.eventPublisher.emitAsync(
|
||||
events.pdfTemplate.onAssigningDefault,
|
||||
{
|
||||
tenantId,
|
||||
templateId,
|
||||
}
|
||||
);
|
||||
await PdfTemplate.query(trx)
|
||||
.where('resource', oldPdfTempalte.resource)
|
||||
.patch({ default: false });
|
||||
@@ -41,6 +49,7 @@ export class AssignPdfTemplateDefault {
|
||||
.findById(templateId)
|
||||
.patch({ default: true });
|
||||
|
||||
// Triggers `onPdfTemplateAssignedDefault` event.
|
||||
await this.eventPublisher.emitAsync(
|
||||
events.pdfTemplate.onAssignedDefault,
|
||||
{
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
import * as R from 'ramda';
|
||||
import HasTenancyService from '../Tenancy/TenancyService';
|
||||
import { Inject, Service } from 'typedi';
|
||||
|
||||
@Service()
|
||||
export class BrandingTemplateDTOTransformer {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Associates the default branding template id.
|
||||
* @param {number} tenantId
|
||||
* @param {string} resource
|
||||
* @param {Record<string, any>} object
|
||||
* @param {string} attributeName
|
||||
* @returns
|
||||
*/
|
||||
public assocDefaultBrandingTemplate = (
|
||||
tenantId: number,
|
||||
resource: string,
|
||||
) => async (object: Record<string, any>) => {
|
||||
const { PdfTemplate } = this.tenancy.models(tenantId);
|
||||
const attributeName = 'pdfTemplateId';
|
||||
|
||||
const defaultTemplate = await PdfTemplate.query().findOne({
|
||||
resource,
|
||||
default: true,
|
||||
});
|
||||
console.log(defaultTemplate);
|
||||
|
||||
if (!defaultTemplate) {
|
||||
return object;
|
||||
}
|
||||
return {
|
||||
...object,
|
||||
[attributeName]: defaultTemplate.id,
|
||||
};
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user