Add company name and logo to documents

Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
Sacha Al Himdani
2025-10-08 16:04:27 +02:00
parent 9bdecdf232
commit d757c9604b
23 changed files with 1391 additions and 203 deletions

View File

@@ -141,6 +141,7 @@ func (s *DocumentService) exportPDFData(
document := &coredata.Document{}
version := &coredata.DocumentVersion{}
owner := &coredata.People{}
organization := &coredata.Organization{}
err := s.svc.pg.WithConn(
ctx,
@@ -161,6 +162,10 @@ func (s *DocumentService) exportPDFData(
return fmt.Errorf("cannot load document owner: %w", err)
}
if err := organization.LoadByID(ctx, conn, s.svc.scope, document.OrganizationID); err != nil {
return fmt.Errorf("cannot load organization: %w", err)
}
return nil
},
)
@@ -177,13 +182,28 @@ func (s *DocumentService) exportPDFData(
classification = docgen.ClassificationSecret
}
horizontalLogoBase64 := ""
if organization.HorizontalLogoFileID != nil {
fileRecord := &coredata.File{}
fileErr := s.svc.pg.WithConn(ctx, func(conn pg.Conn) error {
return fileRecord.LoadByID(ctx, conn, s.svc.scope, *organization.HorizontalLogoFileID)
})
if fileErr == nil {
base64Data, mimeType, logoErr := s.svc.fileManager.GetFileBase64(ctx, fileRecord)
if logoErr == nil {
horizontalLogoBase64 = fmt.Sprintf("data:%s;base64,%s", mimeType, base64Data)
}
}
}
docData := docgen.DocumentData{
Title: version.Title,
Content: version.Content,
Version: version.VersionNumber,
Classification: classification,
Approver: owner.FullName,
PublishedAt: version.PublishedAt,
Title: version.Title,
Content: version.Content,
Version: version.VersionNumber,
Classification: classification,
Approver: owner.FullName,
PublishedAt: version.PublishedAt,
CompanyHorizontalLogoBase64: horizontalLogoBase64,
}
htmlContent, err := docgen.RenderHTML(docData)