diff --git a/.env.example b/.env.example index f4ed27c..5ee2592 100644 --- a/.env.example +++ b/.env.example @@ -4,3 +4,4 @@ MY_SQL_DB=educa7ls MY_SQL_PORT=3306 MY_SQL_HOST=localhost APP_PORT=3000 +SUNAT_API_KEY=apis-token-1.aTSI1U7KEuT-6bbbCguH-4Y8TI6KS73N diff --git a/src/controller/person/person.service.ts b/src/controller/person/person.service.ts index f06f65e..5110d0f 100644 --- a/src/controller/person/person.service.ts +++ b/src/controller/person/person.service.ts @@ -1,9 +1,9 @@ -import { Injectable, InternalServerErrorException, NotFoundException } from "@nestjs/common"; +import { Injectable, NotFoundException } from "@nestjs/common"; import { PersonDto } from "./person.dto"; import { DataSource, Repository } from "typeorm"; import { Persona } from "../../model/Persona/persona.entity"; import { Person } from "../../types/Person"; -import axios from "axios"; +import axios, {AxiosError} from "axios"; import { waitForSunatApi } from "./SunatQueue"; interface SunatPerson { @@ -61,8 +61,7 @@ export class PersonService { }; } - // TODO: Move to env variables - const token = "apis-token-1.aTSI1U7KEuT-6bbbCguH-4Y8TI6KS73N"; + const token = process.env.SUNAT_API_KEY; // Search person in SUNAT API let personSunat: SunatPerson | null = null; @@ -79,7 +78,11 @@ export class PersonService { }, }); personSunat = personSunatR.data; - } catch (e) { /* empty */ + } catch (e) { + const axiosError = e as AxiosError; + if (axiosError.response && axiosError.status === 429) { + console.error(`Axios Sunat API rate limit (${dni})`); + } } diff --git a/src/views/components/Search.tsx b/src/views/components/Search.tsx index 201f632..0098c2d 100644 --- a/src/views/components/Search.tsx +++ b/src/views/components/Search.tsx @@ -122,6 +122,25 @@ function InputBox(props: { }) { const [successAnimation, setSuccessAnimation] = createSignal(false); + const inputElement = ( + props.setDni(e.target.value)} + disabled={props.loading} + /> + ); + const copyToClipboard: HTMLButtonEvent = (ev) => { ev.preventDefault(); @@ -136,26 +155,12 @@ function InputBox(props: { ev.preventDefault(); props.setDni(""); + (inputElement as HTMLInputElement).focus(); }; return (
- props.setDni(e.target.value)} - disabled={props.loading} - /> + {inputElement}