Loading backend/src/database-seeder/database-seeder.module.ts +2 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import { PointOfInterestTraduction } from 'src/pointOfInterest/entities/PointOfI import { CategoryService } from 'src/category/category.service'; import { Category } from 'src/category/entities/category.entity'; import { AdminResetCode } from 'src/auth/admin/entitites/admin-reset-code.entity'; import { PdfService } from 'src/pdf/pdf.service'; @Module({ providers: [ Loading @@ -34,6 +35,7 @@ import { AdminResetCode } from 'src/auth/admin/entitites/admin-reset-code.entity PointOfInterestService, PlaceService, CategoryService, PdfService, ], imports: [ TypeOrmModule.forFeature([ Loading backend/src/pointOfInterest/PointOfInterest.module.ts +10 −1 Original line number Diff line number Diff line Loading @@ -15,10 +15,19 @@ import { EncryptionService } from 'src/auth/encryption/encryption.service'; import { AdminService } from 'src/admin/admin.service'; import { Admin } from 'src/admin/entities/admin.entity'; import { AdminResetCode } from 'src/auth/admin/entitites/admin-reset-code.entity'; import { PdfService } from 'src/pdf/pdf.service'; @Module({ controllers: [PointOfInterestController], providers: [PointOfInterestService, PlaceService, AdminService, AuthAdminService, JwtService, EncryptionService], providers: [ PointOfInterestService, PlaceService, AdminService, AuthAdminService, JwtService, EncryptionService, PdfService, ], imports: [ TypeOrmModule.forFeature([ PointOfInterest, Loading backend/src/pointOfInterest/PointOfInterest.service.ts +25 −19 Original line number Diff line number Diff line Loading @@ -14,12 +14,12 @@ import { createReadStream, readFileSync } from 'fs'; import { join } from 'path'; import { generateQRCode } from './utils/qrcode'; import { Place } from 'src/place/entities/place.entity'; import puppeteer from 'puppeteer'; import { printPointInfo } from './dto/printPointInfo.dto'; import * as fs from 'fs'; import axios from 'axios'; import * as uuid from 'uuid'; import { GoogleConstants } from 'src/constants/google.constants'; import { PdfService } from 'src/pdf/pdf.service'; @Injectable() export class PointOfInterestService { Loading @@ -29,6 +29,7 @@ export class PointOfInterestService { private readonly placeService: PlaceService, @InjectRepository(Place) private placeRepository: Repository<Place>, @InjectDataSource() private dataSource: DataSource, private readonly pdfService: PdfService, ) {} async create(createPointAndTradDto: CreatePointAndTradDto) { const placeRelation = await this.placeRepository.findOne({ Loading Loading @@ -229,26 +230,25 @@ export class PointOfInterestService { async generatePdf(idPlace: number, pointsId: number[]): Promise<Buffer> { const points = await this.findAllByIds(idPlace, pointsId); const htmlContent = this.generateHtml(points); const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setContent(htmlContent); const pdfBuffer = await page.pdf({ format: 'A4', margin: { top: '10mm', bottom: '10mm', left: '10mm', right: '10mm' }, // Márgenes }); await browser.close(); return Buffer.from(pdfBuffer); const pdfBuffer = await this.pdfService.generatePdf(htmlContent); return pdfBuffer; } private generateHtml(points: printPointInfo[]): string { let cardsHtml = ''; let pageCount = 0; for (const point of points) { const filePath = join(ServerConstants.ROOT_STATIC_PATH, 'qr', point.idPoint.toString() + '.png'); if (pageCount % 3 === 0) { if (pageCount > 0) { cardsHtml += '</div>'; // Close previous page } cardsHtml += '<div class="page">'; // Start new page } cardsHtml += ` <div class="card"> <img class="background" src="data:image/jpeg;base64,${readFileSync( Loading @@ -261,8 +261,12 @@ export class PointOfInterestService { <img src="data:image/jpeg;base64,${readFileSync(filePath).toString('base64')}" class="qr-code"/> </div> `; pageCount++; } cardsHtml += '</div>'; // Close the last page return ` <!DOCTYPE html> <html> Loading @@ -277,15 +281,17 @@ export class PointOfInterestService { height: 8cm; page-break-inside: avoid; position: relative; margin: 2cm; } .content{ margin: 2cm; position: absolute; } .qr-code{ width: 4cm; height: 4cm; width: 25%; height: auto; position: absolute; right: 1.5cm; top: 0; Loading @@ -304,21 +310,21 @@ export class PointOfInterestService { } @page { size: A4; margin: 10mm; size: letter; margin: 20mm; } .page { display: flex; flex-wrap: wrap; margin: 2cm; justify-content: space-between; height: calc(100vh - 20mm); page-break-after: always; } </style> </head> <body> <div class="page"> ${cardsHtml} </div> </body> </html> `; Loading Loading
backend/src/database-seeder/database-seeder.module.ts +2 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import { PointOfInterestTraduction } from 'src/pointOfInterest/entities/PointOfI import { CategoryService } from 'src/category/category.service'; import { Category } from 'src/category/entities/category.entity'; import { AdminResetCode } from 'src/auth/admin/entitites/admin-reset-code.entity'; import { PdfService } from 'src/pdf/pdf.service'; @Module({ providers: [ Loading @@ -34,6 +35,7 @@ import { AdminResetCode } from 'src/auth/admin/entitites/admin-reset-code.entity PointOfInterestService, PlaceService, CategoryService, PdfService, ], imports: [ TypeOrmModule.forFeature([ Loading
backend/src/pointOfInterest/PointOfInterest.module.ts +10 −1 Original line number Diff line number Diff line Loading @@ -15,10 +15,19 @@ import { EncryptionService } from 'src/auth/encryption/encryption.service'; import { AdminService } from 'src/admin/admin.service'; import { Admin } from 'src/admin/entities/admin.entity'; import { AdminResetCode } from 'src/auth/admin/entitites/admin-reset-code.entity'; import { PdfService } from 'src/pdf/pdf.service'; @Module({ controllers: [PointOfInterestController], providers: [PointOfInterestService, PlaceService, AdminService, AuthAdminService, JwtService, EncryptionService], providers: [ PointOfInterestService, PlaceService, AdminService, AuthAdminService, JwtService, EncryptionService, PdfService, ], imports: [ TypeOrmModule.forFeature([ PointOfInterest, Loading
backend/src/pointOfInterest/PointOfInterest.service.ts +25 −19 Original line number Diff line number Diff line Loading @@ -14,12 +14,12 @@ import { createReadStream, readFileSync } from 'fs'; import { join } from 'path'; import { generateQRCode } from './utils/qrcode'; import { Place } from 'src/place/entities/place.entity'; import puppeteer from 'puppeteer'; import { printPointInfo } from './dto/printPointInfo.dto'; import * as fs from 'fs'; import axios from 'axios'; import * as uuid from 'uuid'; import { GoogleConstants } from 'src/constants/google.constants'; import { PdfService } from 'src/pdf/pdf.service'; @Injectable() export class PointOfInterestService { Loading @@ -29,6 +29,7 @@ export class PointOfInterestService { private readonly placeService: PlaceService, @InjectRepository(Place) private placeRepository: Repository<Place>, @InjectDataSource() private dataSource: DataSource, private readonly pdfService: PdfService, ) {} async create(createPointAndTradDto: CreatePointAndTradDto) { const placeRelation = await this.placeRepository.findOne({ Loading Loading @@ -229,26 +230,25 @@ export class PointOfInterestService { async generatePdf(idPlace: number, pointsId: number[]): Promise<Buffer> { const points = await this.findAllByIds(idPlace, pointsId); const htmlContent = this.generateHtml(points); const browser = await puppeteer.launch(); const page = await browser.newPage(); await page.setContent(htmlContent); const pdfBuffer = await page.pdf({ format: 'A4', margin: { top: '10mm', bottom: '10mm', left: '10mm', right: '10mm' }, // Márgenes }); await browser.close(); return Buffer.from(pdfBuffer); const pdfBuffer = await this.pdfService.generatePdf(htmlContent); return pdfBuffer; } private generateHtml(points: printPointInfo[]): string { let cardsHtml = ''; let pageCount = 0; for (const point of points) { const filePath = join(ServerConstants.ROOT_STATIC_PATH, 'qr', point.idPoint.toString() + '.png'); if (pageCount % 3 === 0) { if (pageCount > 0) { cardsHtml += '</div>'; // Close previous page } cardsHtml += '<div class="page">'; // Start new page } cardsHtml += ` <div class="card"> <img class="background" src="data:image/jpeg;base64,${readFileSync( Loading @@ -261,8 +261,12 @@ export class PointOfInterestService { <img src="data:image/jpeg;base64,${readFileSync(filePath).toString('base64')}" class="qr-code"/> </div> `; pageCount++; } cardsHtml += '</div>'; // Close the last page return ` <!DOCTYPE html> <html> Loading @@ -277,15 +281,17 @@ export class PointOfInterestService { height: 8cm; page-break-inside: avoid; position: relative; margin: 2cm; } .content{ margin: 2cm; position: absolute; } .qr-code{ width: 4cm; height: 4cm; width: 25%; height: auto; position: absolute; right: 1.5cm; top: 0; Loading @@ -304,21 +310,21 @@ export class PointOfInterestService { } @page { size: A4; margin: 10mm; size: letter; margin: 20mm; } .page { display: flex; flex-wrap: wrap; margin: 2cm; justify-content: space-between; height: calc(100vh - 20mm); page-break-after: always; } </style> </head> <body> <div class="page"> ${cardsHtml} </div> </body> </html> `; Loading