This commit is contained in:
Bastian Wagner
2026-03-12 15:09:07 +01:00
parent d5d1e450f3
commit ed2070abd9
4 changed files with 23 additions and 10 deletions

View File

@@ -84,13 +84,11 @@ export class KeyController {
} }
@Post('pdf') @Post('pdf')
async generatePdf(@Body() dto: KeyHandoverDto, @Res() res: Response): Promise<void> { async generatePdf(@Body() dto: KeyHandoverDto, @Res() res: Response) {
const pdfBuffer = await this.pdfService.generatePdf(dto); const pdfBuffer = await this.service.fetchPdf(dto);
res.setHeader('Content-Type', 'application/pdf'); res.setHeader('Content-Type', 'application/pdf');
res.setHeader('Content-Disposition', 'attachment; filename="schluesseluebergabe.pdf"'); res.setHeader('Content-Disposition', 'inline; filename="test.pdf"');
res.setHeader('Content-Length', pdfBuffer.length); res.send(pdfBuffer);
res.end(pdfBuffer);
} }
} }

View File

@@ -8,10 +8,11 @@ import { ConfigService } from '@nestjs/config';
import { MailModule } from '../mail/mail.module'; import { MailModule } from '../mail/mail.module';
import { SseModule } from '../realtime/sse/sse.module'; import { SseModule } from '../realtime/sse/sse.module';
import { PdfModule } from 'src/shared/pdf/pdf.module'; import { PdfModule } from 'src/shared/pdf/pdf.module';
import { HttpModule } from '@nestjs/axios';
@Module({ @Module({
controllers: [KeyController], controllers: [KeyController],
providers: [KeyService, ConfigService], providers: [KeyService, ConfigService],
imports: [DatabaseModule, AuthModule, SharedServiceModule, MailModule, SseModule, PdfModule], imports: [DatabaseModule, AuthModule, SharedServiceModule, MailModule, SseModule, PdfModule, HttpModule],
}) })
export class KeyModule {} export class KeyModule {}

View File

@@ -12,6 +12,9 @@ import { FindOperator, IsNull, Not } from 'typeorm';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import { MailService } from '../mail/mail.service'; import { MailService } from '../mail/mail.service';
import { SseService } from '../realtime/sse/sse.service'; import { SseService } from '../realtime/sse/sse.service';
import { KeyHandoverDto } from 'src/model/dto/key-handover.dto';
import { firstValueFrom } from 'rxjs';
import { HttpService } from '@nestjs/axios';
@Injectable() @Injectable()
export class KeyService { export class KeyService {
@@ -23,7 +26,8 @@ export class KeyService {
private readonly helper: HelperService, private readonly helper: HelperService,
private readonly configService: ConfigService, private readonly configService: ConfigService,
private readonly mailService: MailService, private readonly mailService: MailService,
private readonly sseService: SseService private readonly sseService: SseService,
private readonly httpService: HttpService
) { ) {
console.log("INIT KEYSERVICE") console.log("INIT KEYSERVICE")
} }
@@ -229,4 +233,14 @@ export class KeyService {
this.sendKeysToSSE(k) this.sendKeysToSSE(k)
return k; return k;
} }
async fetchPdf(dto: KeyHandoverDto): Promise<Buffer> {
const response = await firstValueFrom(
this.httpService.post<any>('http://192.168.30.101:3500/pdf/keyhandover',dto, {
responseType: 'arraybuffer',
}),
);
return Buffer.from(response.data);
}
} }

View File

@@ -41,11 +41,11 @@
<mat-datepicker #picker></mat-datepicker> <mat-datepicker #picker></mat-datepicker>
</mat-form-field> </mat-form-field>
<!-- <div style="padding: 8px 0;margin-top: 12px"> <div style="padding: 8px 0;margin-top: 12px">
<mat-slide-toggle formControlName="handoverDocument"> <mat-slide-toggle formControlName="handoverDocument">
Übergabeprotokoll anlegen Übergabeprotokoll anlegen
</mat-slide-toggle> </mat-slide-toggle>
</div> --> </div>
</form> </form>
</mat-dialog-content> </mat-dialog-content>