-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b05ae6a
commit 4130578
Showing
52 changed files
with
2,187 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ yarn.lock | |
node_modules | ||
public | ||
build | ||
dist | ||
|
||
.env | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
> Why do I have a folder named ".vercel" in my project? | ||
The ".vercel" folder is created when you link a directory to a Vercel project. | ||
|
||
> What does the "project.json" file contain? | ||
The "project.json" file contains: | ||
- The ID of the Vercel project that you linked ("projectId") | ||
- The ID of the user or team your Vercel project is owned by ("orgId") | ||
|
||
> Should I commit the ".vercel" folder? | ||
No, you should not share the ".vercel" folder with anyone. | ||
Upon creation, it will be automatically added to your ".gitignore" file. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"projectId":"prj_PBww6CUXhsr2fl8FzgUsq7Cz1hL6","orgId":"team_HvJE0gYTtcSACnAAcBzRuP3L"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
.changeset | ||
.github | ||
.husky | ||
coverage | ||
public | ||
|
||
node_modules | ||
|
||
yarn.lock | ||
package-lock.json | ||
|
||
.eslintrc.json | ||
babel.config.js | ||
eslint.config.mjs | ||
jest.config.ts | ||
.env | ||
.env.example | ||
.prettierrc.json | ||
|
||
.gitignore | ||
.npmignore | ||
.prettierignore | ||
|
||
**/*/*.test.ts | ||
**/*/*.test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Request, Response } from 'express'; | ||
/** | ||
* Fetches dollar prices with average from a remote source. | ||
* | ||
* @param {Request} _ - Express request object (not used). | ||
* @param {Response} res - Express response object to send the response. | ||
* @returns {Promise<void>} - A promise that resolves when the response is sent. | ||
* @throws {Error} - If there is an error obtaining dollar values. | ||
*/ | ||
export declare const getDollar: (_: Request, res: Response) => Promise<void>; | ||
/** | ||
* Fetches specific dollar prices based on the entity name from a remote source. | ||
* | ||
* @param {Request} req - Express request object containing the query parameters. | ||
* @param {Response} res - Express response object to send the response. | ||
* @returns {Promise<void>} - A promise that resolves when the response is sent. | ||
* @throws {Error} - If there is an error obtaining dollar values. | ||
*/ | ||
export declare const getSpecificDollar: (req: Request, res: Response) => Promise<void>; | ||
/** | ||
* Fetches specific prices in dollars based on the amount of bolivars from a remote source. | ||
* | ||
* @param {Request} req - Express request object containing the query parameters. | ||
* @param {Response} res - Express response object to send the response. | ||
* @returns {Promise<void>} - A promise that resolves when the response is sent. | ||
* @throws {Error} - If there is an error obtaining dollar values. | ||
*/ | ||
export declare const calculatorBsToDollar: (req: Request, res: Response) => Promise<void>; | ||
/** | ||
* Fetches specific prices in bolivars based on the amount of dollars from a remote source. | ||
* | ||
* @param {Request} req - Express request object containing the query parameters. | ||
* @param {Response} res - Express response object to send the response. | ||
* @returns {Promise<void>} - A promise that resolves when the response is sent. | ||
* @throws {Error} - If there is an error obtaining dollar values. | ||
*/ | ||
export declare const calculatorDollarToBs: (req: Request, res: Response) => Promise<void>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
var desc = Object.getOwnPropertyDescriptor(m, k); | ||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
desc = { enumerable: true, get: function() { return m[k]; } }; | ||
} | ||
Object.defineProperty(o, k2, desc); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { | ||
Object.defineProperty(o, "default", { enumerable: true, value: v }); | ||
}) : function(o, v) { | ||
o["default"] = v; | ||
}); | ||
var __importStar = (this && this.__importStar) || function (mod) { | ||
if (mod && mod.__esModule) return mod; | ||
var result = {}; | ||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); | ||
__setModuleDefault(result, mod); | ||
return result; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.calculatorDollarToBs = exports.calculatorBsToDollar = exports.getSpecificDollar = exports.getDollar = void 0; | ||
const services_1 = require("../services"); | ||
const resp = __importStar(require("../utils/responses")); | ||
const dotenv_1 = __importDefault(require("dotenv")); | ||
dotenv_1.default.config(); | ||
/** | ||
* Fetches dollar prices with average from a remote source. | ||
* | ||
* @param {Request} _ - Express request object (not used). | ||
* @param {Response} res - Express response object to send the response. | ||
* @returns {Promise<void>} - A promise that resolves when the response is sent. | ||
* @throws {Error} - If there is an error obtaining dollar values. | ||
*/ | ||
const getDollar = async (_, res) => { | ||
try { | ||
// Fetch dollar prices with average from a remote source | ||
const response = await (0, services_1.getDollarPricesWithAverage)(); | ||
// Send successful response | ||
return resp.makeResponsesOkData(res, response, 'Success'); | ||
} | ||
catch (error) { | ||
// Handle error obtaining dollar values | ||
console.error(`Error obtaining dollar values.`, error); | ||
// Send error response | ||
return resp.makeResponsesError(res, new Error('It has been impossible to connect to the server.')); | ||
} | ||
}; | ||
exports.getDollar = getDollar; | ||
/** | ||
* Fetches specific dollar prices based on the entity name from a remote source. | ||
* | ||
* @param {Request} req - Express request object containing the query parameters. | ||
* @param {Response} res - Express response object to send the response. | ||
* @returns {Promise<void>} - A promise that resolves when the response is sent. | ||
* @throws {Error} - If there is an error obtaining dollar values. | ||
*/ | ||
const getSpecificDollar = async (req, res) => { | ||
try { | ||
// Fetch dollar prices with average from a remote source | ||
const prices = await (0, services_1.getDollarPricesWithAverage)(); | ||
const entity = req.query.name; | ||
let response; | ||
if (prices && typeof entity === 'string') { | ||
// Filter entities based on the entity name | ||
response = prices.entities.filter((item) => item.entity.includes(entity)); | ||
} | ||
else { | ||
response = prices?.entities; | ||
} | ||
if (response.length > 1) { | ||
let length = 0; | ||
let average = 0; | ||
response.forEach((item) => { | ||
if (item.info.dollar > 0) { | ||
length = length + 1; | ||
average = item.info.dollar + average; | ||
} | ||
}); | ||
// Calculate average dollar value and update response object | ||
response = { | ||
date: new Date(), | ||
average: average !== 0 ? Number((average / length).toFixed(2)) : 0, | ||
entities: response, | ||
}; | ||
} | ||
else if (response && response.length === 1) { | ||
// Update response object with single entity if only one entity is found | ||
response = response.pop(); | ||
} | ||
else { | ||
// Update response object with simple data. | ||
response = { | ||
date: new Date(), | ||
entities: null, | ||
}; | ||
} | ||
// Send successful response | ||
return resp.makeResponsesOkData(res, response, 'Success'); | ||
} | ||
catch (error) { | ||
// Handle error obtaining dollar values | ||
console.error(`Error obtaining dollar values.`, error); | ||
// Send error response | ||
return resp.makeResponsesError(res, new Error('It has been impossible to connect to the server.')); | ||
} | ||
}; | ||
exports.getSpecificDollar = getSpecificDollar; | ||
/** | ||
* Fetches specific prices in dollars based on the amount of bolivars from a remote source. | ||
* | ||
* @param {Request} req - Express request object containing the query parameters. | ||
* @param {Response} res - Express response object to send the response. | ||
* @returns {Promise<void>} - A promise that resolves when the response is sent. | ||
* @throws {Error} - If there is an error obtaining dollar values. | ||
*/ | ||
const calculatorBsToDollar = async (req, res) => { | ||
try { | ||
// Obtain the amount in bolivars to be calculated in terms of dollars. | ||
const bs = Number(req.query.bs ?? 0); | ||
const entity = req.query.entity ?? null; | ||
if (!bs || bs <= 0) { | ||
return resp.makeResponsesError(res, new Error('You must provide an amount to be calculated.')); | ||
} | ||
let response; | ||
const prices = await (0, services_1.calculateBsToDollar)(bs); | ||
if (prices && entity && typeof entity === 'string') { | ||
// Filter entities based on the entity name | ||
response = prices.filter((item) => item.entity.includes(entity)); | ||
} | ||
else { | ||
response = prices; | ||
} | ||
if (response && response.length > 1) { | ||
let length = 0; | ||
let average = 0; | ||
response.forEach((item) => { | ||
if (item.dollarCalculated > 0) { | ||
length = length + 1; | ||
average = item.dollarCalculated + average; | ||
} | ||
}); | ||
// Calculate average dollar value and update response object | ||
response = { | ||
date: new Date(), | ||
average: average !== 0 ? Number((average / length).toFixed(2)) : 0, | ||
entities: response, | ||
}; | ||
} | ||
else if (response && response.length === 1) { | ||
// Update response object with single entity if only one entity is found | ||
response = response.pop(); | ||
} | ||
else { | ||
// Update response object with simple data. | ||
response = { | ||
date: new Date(), | ||
entities: null, | ||
}; | ||
} | ||
// Send successful response | ||
return resp.makeResponsesOkData(res, response, 'Success'); | ||
} | ||
catch (error) { | ||
// Handle error obtaining dollar values | ||
console.error(`Error obtaining dollar values.`, error); | ||
// Send error response | ||
return resp.makeResponsesError(res, new Error('It has been impossible to connect to the server.')); | ||
} | ||
}; | ||
exports.calculatorBsToDollar = calculatorBsToDollar; | ||
/** | ||
* Fetches specific prices in bolivars based on the amount of dollars from a remote source. | ||
* | ||
* @param {Request} req - Express request object containing the query parameters. | ||
* @param {Response} res - Express response object to send the response. | ||
* @returns {Promise<void>} - A promise that resolves when the response is sent. | ||
* @throws {Error} - If there is an error obtaining dollar values. | ||
*/ | ||
const calculatorDollarToBs = async (req, res) => { | ||
try { | ||
// Obtain the amount in bolivars to be calculated in terms of dollars. | ||
const dollar = Number(req.query.dollar ?? 0); | ||
const entity = req.query.entity ?? null; | ||
if (!dollar || dollar <= 0) { | ||
return resp.makeResponsesError(res, new Error('You must provide an amount to be calculated.')); | ||
} | ||
let response; | ||
const prices = await (0, services_1.calculateDollarToBs)(dollar); | ||
if (prices && entity && typeof entity === 'string') { | ||
// Filter entities based on the entity name | ||
response = prices.filter((item) => item.entity.includes(entity)); | ||
} | ||
else { | ||
response = prices; | ||
} | ||
if (response && response.length > 1) { | ||
let length = 0; | ||
let average = 0; | ||
response.forEach((item) => { | ||
if (item.bolivarCalculated > 0) { | ||
length = length + 1; | ||
average = item.bolivarCalculated + average; | ||
} | ||
}); | ||
// Calculate average dollar value and update response object | ||
response = { | ||
date: new Date(), | ||
average: average !== 0 ? Number((average / length).toFixed(2)) : 0, | ||
entities: response, | ||
}; | ||
} | ||
else if (response && response.length === 1) { | ||
// Update response object with single entity if only one entity is found | ||
response = response.pop(); | ||
} | ||
else { | ||
// Update response object with simple data. | ||
response = { | ||
date: new Date(), | ||
entities: null, | ||
}; | ||
} | ||
// Send successful response | ||
return resp.makeResponsesOkData(res, response, 'Success'); | ||
} | ||
catch (error) { | ||
// Handle error obtaining dollar values | ||
console.error(`Error obtaining dollar values.`, error); | ||
// Send error response | ||
return resp.makeResponsesError(res, new Error('It has been impossible to connect to the server.')); | ||
} | ||
}; | ||
exports.calculatorDollarToBs = calculatorDollarToBs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { Request, Response } from 'express'; | ||
/** | ||
* Fetches euro prices with average from a remote source. | ||
* | ||
* @param {Request} _ - Express request object (not used). | ||
* @param {Response} res - Express response object to send the response. | ||
* @returns {Promise<void>} - A promise that resolves when the response is sent. | ||
* @throws {Error} - If there is an error obtaining euro values. | ||
*/ | ||
export declare const getEuro: (_: Request, res: Response) => Promise<void>; | ||
/** | ||
* Fetches specific euro prices based on the entity name from a remote source. | ||
* | ||
* @param {Request} req - Express request object containing the query parameters. | ||
* @param {Response} res - Express response object to send the response. | ||
* @returns {Promise<void>} - A promise that resolves when the response is sent. | ||
* @throws {Error} - If there is an error obtaining euro values. | ||
*/ | ||
export declare const getSpecificEuro: (req: Request, res: Response) => Promise<void>; | ||
/** | ||
* Fetches specific prices in euros based on the amount of bolivars from a remote source. | ||
* | ||
* @param {Request} req - Express request object containing the query parameters. | ||
* @param {Response} res - Express response object to send the response. | ||
* @returns {Promise<void>} - A promise that resolves when the response is sent. | ||
* @throws {Error} - If there is an error obtaining euro values. | ||
*/ | ||
export declare const calculatorBsToEuro: (req: Request, res: Response) => Promise<void>; | ||
/** | ||
* Fetches specific prices in bolivars based on the amount of euros from a remote source. | ||
* | ||
* @param {Request} req - Express request object containing the query parameters. | ||
* @param {Response} res - Express response object to send the response. | ||
* @returns {Promise<void>} - A promise that resolves when the response is sent. | ||
* @throws {Error} - If there is an error obtaining euro values. | ||
*/ | ||
export declare const calculatorEuroToBs: (req: Request, res: Response) => Promise<void>; |
Oops, something went wrong.
4130578
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
venecodollar – ./
venecodollar-git-main-gustavoeriveros-projects.vercel.app
venecodollar-gustavoeriveros-projects.vercel.app
venecodollar.vercel.app