@ahurein/travel-explorer
Version:
CLI utility to easily browse attractions in every country/city
87 lines (86 loc) • 3.94 kB
JavaScript
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
import axios from 'axios';
import https from 'https';
const log = console.log;
const axiosClient = axios.create({
baseURL: "https://travelexplorer.witfitminds.com/api/v1",
headers: {
"Content-Type": "Application/json"
},
httpsAgent: new https.Agent({ rejectUnauthorized: false })
});
// process.on("uncaughtException", () => log(chalk.red("Encountered an error, try again")))
export const getAttractionsNearYou = (country, page) => __awaiter(void 0, void 0, void 0, function* () {
var _a;
try {
const attractions = yield axiosClient.post("/attractions/near-you", { country, page: Number(page) });
return (_a = attractions.data) === null || _a === void 0 ? void 0 : _a.data;
}
catch (e) {
}
});
export const getAttractionsByCountry = (country, page) => __awaiter(void 0, void 0, void 0, function* () {
var _b;
try {
const attractions = yield axiosClient.post("/attractions/country", { country, page: Number(page) });
return (_b = attractions === null || attractions === void 0 ? void 0 : attractions.data) === null || _b === void 0 ? void 0 : _b.data;
}
catch (e) {
return { message: e.response.data };
}
});
export const getAttractionsByCity = (country, city, page) => __awaiter(void 0, void 0, void 0, function* () {
var _c;
try {
const attractions = yield axiosClient.post("/attractions/city", { country, city, page: Number(page) });
return (_c = attractions === null || attractions === void 0 ? void 0 : attractions.data) === null || _c === void 0 ? void 0 : _c.data;
}
catch (e) {
return { message: e.response.data };
}
});
export const getAttractionsByContinent = (continent, page) => __awaiter(void 0, void 0, void 0, function* () {
var _d;
try {
const attractions = yield axiosClient.post("/attractions/continent", { continent, page: Number(page) });
return (_d = attractions === null || attractions === void 0 ? void 0 : attractions.data) === null || _d === void 0 ? void 0 : _d.data;
}
catch (e) {
return { message: e.response.data };
}
});
export const getContinentTodo = (continent, page) => __awaiter(void 0, void 0, void 0, function* () {
try {
const attractions = yield axiosClient.post("/attractions/continent-things-to-do", { continent, page: Number(page) });
return attractions === null || attractions === void 0 ? void 0 : attractions.data;
}
catch (e) {
return { message: e.response.data };
}
});
export const getCountryTodo = (country, page) => __awaiter(void 0, void 0, void 0, function* () {
try {
const attractions = yield axiosClient.post("/attractions/country-things-to-do", { country, page: Number(page) });
return attractions === null || attractions === void 0 ? void 0 : attractions.data;
}
catch (e) {
return { message: e.response.data };
}
});
export const getAttractionsStats = () => __awaiter(void 0, void 0, void 0, function* () {
try {
const stats = yield axiosClient.get("/attractions/stats");
return stats === null || stats === void 0 ? void 0 : stats.data;
}
catch (e) {
return { message: e.response.data };
}
});