src/module/pdf/subservices/PDFGenerator.schein.ts
Properties |
|
Methods |
|
constructor(studentService: StudentService, scheincriteriaService: ScheincriteriaService, templateService: TemplateService)
|
||||||||||||
Parameters :
|
Public Async generatePDF | |||||
generatePDF(undefined: GeneratorOptions)
|
|||||
Inherited from
PDFGenerator
|
|||||
Defined in
PDFGenerator:30
|
|||||
Generates a PDF which shows a list of all students and their schein status.
Parameters :
Returns :
Promise<Buffer>
Buffer of a PDF containing the list with the schein status of all the given students. |
Private Static getFirstDifferentPosition | ||||||||||||
getFirstDifferentPosition(first: string, second: string)
|
||||||||||||
Inherited from
PDFWithStudentsGenerator
|
||||||||||||
Defined in
PDFWithStudentsGenerator:78
|
||||||||||||
Searches for the position of the first character which both strings DO NOT have in common. This position is then returned.
Parameters :
Returns :
number
The first position in which both string differ. If they are completely equal the length of the first string is returned. |
Protected getShortenedMatriculationNumbers | ||||||||
getShortenedMatriculationNumbers(students: (Student | IStudent)[])
|
||||||||
Inherited from
PDFWithStudentsGenerator
|
||||||||
Defined in
PDFWithStudentsGenerator:20
|
||||||||
Returns the shortened number for all students together with the ID of the student to which the shortened matriculation number belongs to. Those shortened numbers are still enough to identify a student. However, this is only true if one only considers the given students. If one extends that array without re-running this function the identifying feature may get lost.
Parameters :
Returns :
ShortenedMatriculationInfo[]
The shortened but still identifying matriculation numbers of all given students. |
Private Static reverseString | ||||||||
reverseString(string: string)
|
||||||||
Inherited from
PDFWithStudentsGenerator
|
||||||||
Defined in
PDFWithStudentsGenerator:92
|
||||||||
Parameters :
Returns :
string
The reversed string. |
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 :
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 :
Returns :
Promise<string>
|
Private Async putBodyInHTML | ||||||||
putBodyInHTML(body: string)
|
||||||||
Inherited from
PDFGenerator
|
||||||||
Defined in
PDFGenerator:69
|
||||||||
Puts the given body in corresponding a
Parameters :
Returns :
Promise<string>
Complete HTML "file" which contains the given |
Private Readonly logger |
Default value : new Logger(PDFGenerator.name)
|
Inherited from
PDFGenerator
|
Defined in
PDFGenerator:13
|
import { Injectable } from '@nestjs/common';
import { StudentStatus } from 'shared/model/Student';
import { ScheincriteriaService } from '../../scheincriteria/scheincriteria.service';
import { StudentService } from '../../student/student.service';
import { TemplateService } from '../../template/template.service';
import { PassedState, Scheinstatus } from '../../template/template.types';
import { PDFWithStudentsGenerator } from './PDFGenerator.withStudents';
interface GeneratorOptions {
enableShortMatriculationNo: boolean;
}
@Injectable()
export class ScheinResultsPDFGenerator extends PDFWithStudentsGenerator<GeneratorOptions> {
constructor(
private readonly studentService: StudentService,
private readonly scheincriteriaService: ScheincriteriaService,
private readonly templateService: TemplateService
) {
super();
}
/**
* Generates a PDF which shows a list of all students and their schein status.
*
* @param options Determine if the matriculation numbers are shortened or not.
*
* @returns Buffer of a PDF containing the list with the schein status of all the given students.
*/
public async generatePDF({ enableShortMatriculationNo }: GeneratorOptions): Promise<Buffer> {
const summaries = await this.scheincriteriaService.getResultsOfAllStudents();
const students = Object.values(summaries)
.map((s) => s.student)
.filter((student) => !!student.matriculationNo);
const shortenedMatriculationNumbers = this.getShortenedMatriculationNumbers(students);
const statuses: Scheinstatus[] = [];
const template = this.templateService.getScheinstatusTemplate();
shortenedMatriculationNumbers.forEach(({ shortenedNo, studentId }) => {
const summary = summaries[studentId];
let state: PassedState;
if (summary.student.status === StudentStatus.NO_SCHEIN_REQUIRED) {
state = PassedState.ALREADY_HAS_SCHEIN;
} else {
state = summaries[studentId].passed ? PassedState.PASSED : PassedState.NOT_PASSED;
}
if (enableShortMatriculationNo) {
statuses.push({ matriculationNo: shortenedNo, state });
} else {
const matriculationNo = students.find((s) => s.id === studentId)?.matriculationNo;
statuses.push({
matriculationNo: `${matriculationNo} (${shortenedNo})`,
state,
});
}
});
return this.generatePDFFromBodyContent(template({ statuses }));
}
}