@Get("/generate-document/:document_company_id/:document_type") async generateDocumentPDF( @Param("document_company_id") document_company_id: number, @Param("document_type") document_type: string, @Res() res: FastifyReply ) { try { const response = await this.leadsManagementService.generateDocumentPDF(document_company_id, document_type); if (!response?.pdfBuffer || response?.pdfBuffer.length === 0) { throw new Error("Generated PDF is empty."); } return handleSuccess(res, response); } catch (error) { console.error("Error generating document PDF:", error); return res.status(500).send({ success: false, message: "Failed to generate PDF." }); } } @Post("/documents-data") async addDocumentsData( @Body() body: any, @Req() req: FastifyRequest, @Res() res: FastifyReply ) { try { const id = 64; if (!body.document_type) { return res.status(400).send({ message: "document_type is required" }); } const response = await this.leadsManagementService.addDocumentsData(id, body); return handleSuccess(res, response); } catch (error) { console.error("Error adding documents:", error); return res.status(500).send({ message: "Error adding documents", error: error.message }); } } @Post('/send-client-email') async send_client_email( @Body() body: any, @Req() req: FastifyRequest, @Res() reply: FastifyReply, ) { try { const res = await this.leadsManagementService.send_email(req,body); reply.send({ success: true, res, }); } catch (error) { console.log('error: ', error); reply.send({ success: false, error: String(error), }); } }