Commit 61e8c173 authored by Omar Luna Hernández's avatar Omar Luna Hernández
Browse files

Se agrega la lógica para obtener el pdf para imprimir

parent 6b8c9724
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
import axios from "axios";
import { PoiDatasourceInf } from "../../../infraestructure/datasources/poi_repository";
import { Buffer } from "buffer";
import { PoiDatasourceInf } from "../../../infraestructure/datasources/poi_datasource";
import { PointOfInterest } from "../../../infraestructure/entities/poi";
import { APIUrl } from "../../../constants/api_url";
import { API_ROUTE_PLACE, API_ROUTE_POINT } from "../../../constants/api_routes";
@@ -56,4 +57,14 @@ export class POIDatasourceProd implements PoiDatasourceInf{

    return poi;
  }

  async getPDFByPoints(idPlace: number, pointsId: number[]): Promise<string> {
    const {data} = await axios.get(APIUrl + API_ROUTE_PLACE + `/${idPlace}` + API_ROUTE_POINT + '/generate', {
      params: {
        pointsId: pointsId.join(',')
      },
      responseType: 'arraybuffer'
    });
    return Buffer.from(data, 'binary').toString('base64');
  }
}
 No newline at end of file
+5 −1
Original line number Diff line number Diff line
import { PoiDatasourceInf } from "../../../infraestructure/datasources/poi_repository";
import { PoiDatasourceInf } from "../../../infraestructure/datasources/poi_datasource";
import { PointOfInterest } from "../../../infraestructure/entities/poi";
import { PoiRepositoryInf } from "../../../infraestructure/repositories/poi_repository";

@@ -18,4 +18,8 @@ export class POIRepositoryProd implements PoiRepositoryInf{
  async getPOIsByPlace(idPlace: number): Promise<PointOfInterest[]> {
    return this.datasouce.getPOIsByPlace(idPlace);
  }

  async getPDFByPoints(idPlace: number, pointsId: number[]): Promise<string> {
    return this.datasouce.getPDFByPoints(idPlace, pointsId);
  }
}
 No newline at end of file
+15 −1
Original line number Diff line number Diff line
@@ -142,6 +142,19 @@ setIsWindowActive?: (visibility: boolean) => void) => {
    }
  }

  const getPdfById = async (idPlace: number, pointsId: number[]): Promise<string | null> => {
    try{
      const pdfUrl = await POIRepository.getPDFByPoints(idPlace, pointsId);
      return pdfUrl;
    }catch(error: any){
      if(axios.isAxiosError(error)){
        error as AxiosError;
        showErrorAxios(error);
      }
    }
    return null;
  }

  const getPointById = async (idPoint: number): Promise<PointOfInterest | null> => {
    try{
      const point = await POIRepository.getPOIById(idPoint);
@@ -174,6 +187,7 @@ setIsWindowActive?: (visibility: boolean) => void) => {
    poiList,
    pending,
    getPointById,
    updatePOIByPlace
    updatePOIByPlace,
    getPdfById
  };
}
+1 −0
Original line number Diff line number Diff line
@@ -4,4 +4,5 @@ export interface PoiDatasourceInf {
  registerPoint(form: PointOfInterest): Promise<void>;
  getPOIsByPlace(idPlace: number): Promise<PointOfInterest[]>;
  getPOIById(idPoint: number): Promise<PointOfInterest>;
  getPDFByPoints(idPlace: number, pointsId: number[]): Promise<string>;
}
 No newline at end of file
+1 −0
Original line number Diff line number Diff line
@@ -4,4 +4,5 @@ export interface PoiRepositoryInf {
  registerPoint(form: PointOfInterest): Promise<void>;
  getPOIsByPlace(idPlace: number): Promise<PointOfInterest[]>;
  getPOIById(idPoint: number): Promise<PointOfInterest>;
  getPDFByPoints(idPlace: number, pointsId: number[]): Promise<string>;
}
 No newline at end of file