File

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

Extends

PDFGenerator

Index

Properties
Methods

Constructor

constructor(tutorialService: TutorialService, templateService: TemplateService)
Parameters :
Name Type Optional
tutorialService TutorialService No
templateService TemplateService No

Methods

Public Async generatePDF
generatePDF(undefined: GeneratorOptions)
Inherited from PDFGenerator
Defined in PDFGenerator:32

Generates a PDF which contains a list with all students of the given tutorial. This list contains one empty column for signings.

Parameters :
Name Type Optional
GeneratorOptions No
Returns : Promise<Buffer>

Buffer containing a PDF with a list for attendances.

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 { BadRequestException, Injectable } from '@nestjs/common';
import { DateTime } from 'luxon';
import { getNameOfEntity, sortByName } from 'shared/util/helpers';
import { TemplateService } from '../../template/template.service';
import { TutorialService } from '../../tutorial/tutorial.service';
import { PDFGenerator } from './PDFGenerator.core';

interface GeneratorOptions {
    tutorialId: string;
    date: DateTime;
}

@Injectable()
export class AttendancePDFGenerator extends PDFGenerator<GeneratorOptions> {
    constructor(
        private readonly tutorialService: TutorialService,
        private readonly templateService: TemplateService
    ) {
        super();
    }

    /**
     * Generates a PDF which contains a list with all students of the given tutorial. This list contains one empty column for signings.
     *
     * @param options Must contain the tutorialId and the date.
     *
     * @returns Buffer containing a PDF with a list for attendances.
     *
     * @throws `NotFoundException` - If no tutorial with the given ID could be found.
     * @throws `BadRequestException` - If the tutorial does not have a tutor assigned to it.
     */
    public async generatePDF({ tutorialId, date }: GeneratorOptions): Promise<Buffer> {
        const tutorial = await this.tutorialService.findById(tutorialId);

        if (tutorial.tutors.getItems().length === 0) {
            throw new BadRequestException(
                'Tutorial which attendance list should be generated does NOT have a tutor assigned.'
            );
        }

        const { tutors, slot: tutorialSlot } = tutorial;
        const tutorNames = tutors
            .getItems()
            .map((tutor) => getNameOfEntity(tutor))
            .join('; ');
        const template = this.templateService.getAttendanceTemplate();
        const students = tutorial.getStudents();
        const content = template({
            date,
            students: students.sort(sortByName).map((s) => ({ name: getNameOfEntity(s) })),
            tutorNames,
            tutorialSlot,
        });

        return this.generatePDFFromBodyContent(content);
    }
}

results matching ""

    No results matching ""