This commit is contained in:
@@ -84,13 +84,11 @@ export class KeyController {
|
||||
}
|
||||
|
||||
@Post('pdf')
|
||||
async generatePdf(@Body() dto: KeyHandoverDto, @Res() res: Response): Promise<void> {
|
||||
const pdfBuffer = await this.pdfService.generatePdf(dto);
|
||||
async generatePdf(@Body() dto: KeyHandoverDto, @Res() res: Response) {
|
||||
const pdfBuffer = await this.service.fetchPdf(dto);
|
||||
|
||||
res.setHeader('Content-Type', 'application/pdf');
|
||||
res.setHeader('Content-Disposition', 'attachment; filename="schluesseluebergabe.pdf"');
|
||||
res.setHeader('Content-Length', pdfBuffer.length);
|
||||
|
||||
res.end(pdfBuffer);
|
||||
res.setHeader('Content-Disposition', 'inline; filename="test.pdf"');
|
||||
res.send(pdfBuffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,10 +8,11 @@ import { ConfigService } from '@nestjs/config';
|
||||
import { MailModule } from '../mail/mail.module';
|
||||
import { SseModule } from '../realtime/sse/sse.module';
|
||||
import { PdfModule } from 'src/shared/pdf/pdf.module';
|
||||
import { HttpModule } from '@nestjs/axios';
|
||||
|
||||
@Module({
|
||||
controllers: [KeyController],
|
||||
providers: [KeyService, ConfigService],
|
||||
imports: [DatabaseModule, AuthModule, SharedServiceModule, MailModule, SseModule, PdfModule],
|
||||
imports: [DatabaseModule, AuthModule, SharedServiceModule, MailModule, SseModule, PdfModule, HttpModule],
|
||||
})
|
||||
export class KeyModule {}
|
||||
|
||||
@@ -12,6 +12,9 @@ import { FindOperator, IsNull, Not } from 'typeorm';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import { MailService } from '../mail/mail.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()
|
||||
export class KeyService {
|
||||
@@ -23,7 +26,8 @@ export class KeyService {
|
||||
private readonly helper: HelperService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly mailService: MailService,
|
||||
private readonly sseService: SseService
|
||||
private readonly sseService: SseService,
|
||||
private readonly httpService: HttpService
|
||||
) {
|
||||
console.log("INIT KEYSERVICE")
|
||||
}
|
||||
@@ -229,4 +233,14 @@ export class KeyService {
|
||||
this.sendKeysToSSE(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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,11 +41,11 @@
|
||||
<mat-datepicker #picker></mat-datepicker>
|
||||
</mat-form-field>
|
||||
|
||||
<!-- <div style="padding: 8px 0;margin-top: 12px">
|
||||
<div style="padding: 8px 0;margin-top: 12px">
|
||||
<mat-slide-toggle formControlName="handoverDocument">
|
||||
Übergabeprotokoll anlegen
|
||||
</mat-slide-toggle>
|
||||
</div> -->
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</mat-dialog-content>
|
||||
|
||||
Reference in New Issue
Block a user