File

src/module/pdf/subservices/PDFGenerator.credentials.ts

Extends

PDFGenerator

Index

Properties
Methods

Constructor

constructor(userService: UserService, templateService: TemplateService)
Parameters :
Name Type Optional
userService UserService No
templateService TemplateService No

Methods

Public Async generatePDF
generatePDF()
Inherited from PDFGenerator
Defined in PDFGenerator:21

Generates a PDF containing a list with all the given users and their temporary passwords.

Returns : Promise<Buffer>

Buffer containing the PDF with the temporary passwords of the given users.

Protected Async generatePDFFromBodyContent
generatePDFFromBodyContent(body: string)
Inherited from PDFGenerator
Defined in PDFGenerator:31

Generates a PDF from the given body. The body gets put in an HTML wrapper first.

Parameters :
Name Type Optional Description
body string No

Body content to be put in the PDF as HTML body.

Returns : Promise<Buffer>

Buffer containing the generated PDF.

Private Static getCustomCSS
getCustomCSS()
Inherited from PDFGenerator
Defined in PDFGenerator:114
Returns : string

Some small customizations to the GitHub markdown CSS.

Private Async getGithubMarkdownCSS
getGithubMarkdownCSS()
Inherited from PDFGenerator
Defined in PDFGenerator:88
Returns : Promise<string>

The GitHub markdown CSS.

Private Async getHighlightCSS
getHighlightCSS()
Inherited from PDFGenerator
Defined in PDFGenerator:95
Returns : Promise<string>

The HighlightJS CSS.

Private Async loadCSSFile
loadCSSFile(moduleName: string)
Inherited from PDFGenerator
Defined in PDFGenerator:99
Parameters :
Name Type Optional
moduleName string No
Returns : Promise<string>
Private Async putBodyInHTML
putBodyInHTML(body: string)
Inherited from PDFGenerator
Defined in PDFGenerator:69

Puts the given body in corresponding a <body> element. The returned string is a complete HTML "file" with slightly customized GitHub Markdown CSS.

Parameters :
Name Type Optional Description
body string No

Body to embed in HTML.

Returns : Promise<string>

Complete HTML "file" which contains the given body as body.

Properties

Private Readonly logger
Default value : new Logger(PDFGenerator.name)
Inherited from PDFGenerator
Defined in PDFGenerator:13
import { Injectable } from '@nestjs/common';
import { getNameOfEntity, sortByName } from '../../../shared/util/helpers';
import { TemplateService } from '../../template/template.service';
import { UserService } from '../../user/user.service';
import { PDFGenerator } from './PDFGenerator.core';

@Injectable()
export class CredentialsPDFGenerator extends PDFGenerator {
    constructor(
        private readonly userService: UserService,
        private readonly templateService: TemplateService
    ) {
        super();
    }

    /**
     * Generates a PDF containing a list with all the given users and their temporary passwords.
     *
     * @returns Buffer containing the PDF with the temporary passwords of the given users.
     */
    public async generatePDF(): Promise<Buffer> {
        const users = await this.userService.findAll();
        const template = this.templateService.getCredentialsTemplate();

        return this.generatePDFFromBodyContent(
            template({
                users: users.sort(sortByName).map((u) => ({
                    name: getNameOfEntity(u),
                    username: u.username,
                    password: u.temporaryPassword,
                })),
            })
        );
    }
}

results matching ""

    No results matching ""