Skip to content
Snippets Groups Projects
Commit ed81c7ff authored by hugcubi's avatar hugcubi
Browse files

Inclusión de más managers y clients

parent 6ecd531e
No related branches found
No related tags found
1 merge request!36Develop
export const env = {
authApi: "http://localhost:8101/",
userApi: "http://localhost:8201/users",
exports.env = {
authApi: "http://localhost:8101/auth",
hotelsApi: "http://localhost:8301/hotels",
bookingsApi: "http://localhost:8401/bookings",
};
export const env = {
authApi: "http://localhost:8101/",
userApi: "http://localhost:8201/users",
hotelsApi: "http://localhost:8301/hotels",
bookingsApi: "http://localhost:8401/bookings",
};
exports.env = {
authApi: "http://kong:8000/api/auth",
hotelsApi: "http://kong:8000/api/hotels",
bookingsApi: "http://kong:8000/api/bookings",
};
const mockedUsers = require("./mocks/users.json");
const mockedHotels = require("./mocks/hotels.json");
const mockedBookings = require("./mocks/bookings.json");
const axios = require("axios");
const { jwtDecode } = require("jwt-decode");
const dev = require("./environments/env");
const prod = require("./environments/env.production");
// Modo
const args = process.argv;
const isProduction = args.includes("--prod");
const DEBUG = args.includes("--debug");
const authUrl = "http://localhost:8101/auth";
const hotelsUrl = "http://localhost:8301/hotels";
const bookingUrl = "http://localhost:8401/bookings";
const env = isProduction ? prod : dev;
const { authApi, hotelsApi, bookingsApi } = env;
const debug = (...values) => {
if (DEBUG) console.log(...values);
};
const loj = (data) => {
console.log(JSON.stringify(data, null, 2));
......@@ -53,11 +58,12 @@ const savePost = async (data, first, second = "") => {
try {
return await axios.post(first, data);
} catch (error) {
console.error("ERROR 1");
console.error("ERROR Al REGISTRO");
return await axios.post(second, data);
}
} catch (error) {
console.error("ERROR 2");
console.error("ERROR Al LOGIN");
console.error("\nNo se ha podido comunicar con el servicio de auth");
process.exit(-1);
}
};
......@@ -65,8 +71,8 @@ const savePost = async (data, first, second = "") => {
async function register(user) {
const { data } = await savePost(
user,
`${authUrl}/register`,
`${authUrl}/login`
`${authApi}/register`,
`${authApi}/login`
);
const decoded = jwtDecode(data.token);
user.id = decoded.id;
......@@ -87,7 +93,7 @@ const addUsers = async () => {
};
const insertHotel = async ({ manager, hotel }) => {
const { data } = await axios.post(hotelsUrl, {
const { data } = await axios.post(hotelsApi, {
...hotel,
managerId: manager.id,
});
......@@ -104,8 +110,7 @@ async function addHotels(managers) {
}
const insertBookings = async (booking) => {
console.log({ booking });
const { data } = await axios.post(bookingUrl, booking);
const { data } = await axios.post(bookingsApi, booking);
return data;
};
......@@ -131,10 +136,12 @@ async function addBookings(clients, hotels) {
}
async function init() {
debug("MODE:", isProduction ? "PRODUCTION" : "DEVELOPMENT");
debug("ENV:", env.env, "\n");
const { managers, clients } = await addUsers();
const hotels = await addHotels(managers, 3);
await addBookings(clients, hotels);
console.log("POBLACIÓN COMPLETADA EXITOSAMENTE");
}
console.log("MODE:", isProduction ? "PRODUCTION" : "DEVELOPMENT");
init();
......@@ -6,14 +6,32 @@
"rol": "ADMIN"
},
{
"name": "Hotel",
"email": "hotel@dev.com",
"name": "Hotel 1",
"email": "hotel1@dev.com",
"password": "123",
"rol": "HOTEL_ADMIN"
},
{
"name": "Client",
"email": "client@dev.com",
"name": "Hotel 2",
"email": "hotel2@dev.com",
"password": "123",
"rol": "HOTEL_ADMIN"
},
{
"name": "Client 1",
"email": "client1@dev.com",
"password": "123",
"rol": "CLIENT"
},
{
"name": "Client 2",
"email": "client2@dev.com",
"password": "123",
"rol": "CLIENT"
},
{
"name": "Client 3",
"email": "client3@dev.com",
"password": "123",
"rol": "CLIENT"
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment