Skip to content

Commit

Permalink
se implementó la funcionalidad que obtiene los valores para dolar y e…
Browse files Browse the repository at this point in the history
…uro al día
  • Loading branch information
s100tist committed Jun 11, 2024
1 parent 8cd7cac commit 9bb20a9
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 5 deletions.
29 changes: 29 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const express_1 = __importDefault(require("express"));
const obtener_tasa_1 = require("./obtener_tasa");
const app = (0, express_1.default)();
const port = 4010;
app.get('/', (req, res) => {
res.send('Hello, TypeScript with Express!');
});
app.get('/tasa_de_cambio', async (req, res) => {
try {
const data = await (0, obtener_tasa_1.obtener_tasa_de_cambio)();
res.json(data);
}
catch (error) {
if (error instanceof Error) {
res.status(500).json({ message: error.message });
}
else {
res.status(500).json({ message: 'An unknown error occurred' });
}
}
});
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
20 changes: 20 additions & 0 deletions dist/obtener_tasa.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.obtener_tasa_de_cambio = void 0;
//SF43718 dolar
//SF46410 euro
const token_1 = require("./token");
async function obtener_tasa_de_cambio() {
var url = "https://www.banxico.org.mx/SieAPIRest/service/v1/series/SF46410%2CSF43718/datos/oportuno";
const response = await fetch(url, {
method: "GET",
headers: {
"Content-type": "application/json; charset=UTF-8",
"Bmx-Token": token_1.token
}
});
const json = await response.json();
return json;
}
exports.obtener_tasa_de_cambio = obtener_tasa_de_cambio;
;
4 changes: 4 additions & 0 deletions dist/token.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.token = void 0;
exports.token = 'c355bd604fb1ac3e65ed97187b63a6232f5be74f6da89434e53799aea3ee7620';
16 changes: 15 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
import express from 'express';

import { obtener_tasa_de_cambio } from './obtener_tasa';
const app = express();
const port = 4010;

app.get('/', (req, res) => {
res.send('Hello, TypeScript with Express!');
});


app.get('/tasa_de_cambio', async (req, res) => {
try {
const data = await obtener_tasa_de_cambio();
res.json(data);
} catch (error: unknown) {
if (error instanceof Error) {
res.status(500).json({ message: error.message });
} else {
res.status(500).json({ message: 'An unknown error occurred' });
}
}
});

app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
11 changes: 8 additions & 3 deletions src/obtener_tasa.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
async function obtener_tasa_de_cambio(){
var url = "http://localhost/frontend/api/empresas/empresas.php";
//SF43718 dolar
//SF46410 euro
import { token } from "./token";
export async function obtener_tasa_de_cambio(){
var url = "https://www.banxico.org.mx/SieAPIRest/service/v1/series/SF46410%2CSF43718/datos/oportuno";

const response = await fetch(url, {
method: "GET",
headers: {
"Content-type": "application/json; charset=UTF-8"
"Content-type": "application/json; charset=UTF-8",
"Bmx-Token": token

}
});
const json = await response.json();
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"esModuleInterop": true,
"skipLibCheck": true,
"forceConsistentCasingInFileNames": true,
"outDir": "./dist"
"outDir": "./dist",
"rootDir": "./src"
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules"]
Expand Down

0 comments on commit 9bb20a9

Please sign in to comment.