-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
129 lines (106 loc) · 3.58 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
require("firebase/firestore");
require("firebase/storage");
const express = require("express");
var app = express(); // Express();
app.use(express.json());
const port = 3001;
const fetch = require("node-fetch");
const server = "localhost:3000";
// Import
const Reviews = require("./model/Reviews.js");
const Users = require("./model/Users.js");
const Restaurants = require("./model/Restaurants.js");
const users = require("./routes/usersRoutes");
const reviews = require("./routes/reviewsRoutes");
const places = require("./routes/placesRoutes");
// GET , PUT, POST, DELETE
function listNamesIds(data) {
data.forEach((restaurant) => {
console.log(restaurant.name);
});
}
// async function testCreateReview(username, placeId, rating, review) {
// reviewId = await Reviews.ReviewsAPI.createReview(
// username,
// placeId,
// rating,
// review
// );
// console.log(JSON.stringify(reviewId));
// }
// testCreateReview(
// "johndoe",
// "ChIJdxxU1WeuEmsR11c4fswX-I",
// 1,
// "I hated Aria Restaurant Sydney!"
// );
// restaurant: Google place API json object for a restaurant
// return -> a list of reviews for that restaurant
async function testGetReviews() {
var revs = await Reviews.ReviewsAPI.getReviews(
"ChIJdxxU1WeuEmsR11c4fswX-Io"
);
return Promise.all(revs).then((rev) => {
return { reviews: rev };
});
}
// async function testGetRestaurants() {
// var rests = await Restaurants.RestaurantsAPI.searchRestaurants(
// "Sydney",
// ""
// );
// return Promise.all([rests]).then((rest) => {
// return rests;
// });
// }
// async function testGetToken() {
// return await Restaurants.RestaurantsAPI.getNextPage("Sydney", "");
// }
// THIS IS HOW THE FRONTEND WILL CALL
async function itWorks() {
// const user = await Users.UsersAPI.login("tyus", "1234");
// console.log("user login call returns: ", user);
const reviews = await testGetReviews();
console.log("testGetReviews call returns: " + reviews);
// const rests = await testGetRestaurants();
// console.log("testGetRestaurants call returns: " + rests);
// const token = await testGetToken();
// console.log("testGetToken call returns: " + token);
}
itWorks();
// console.log("usersAPI call returns: " + JSON.parse(Users.UsersAPI.login("tysu", "1234")));
// async function testGetReviews2() {
// await testGetReviews().then((hello) => {
// return { reviews: hello };
// });
// }
// Promise.all([testGetReviews2()]).then((hello) => {
// console.log("please work " + hello);
// });
// var json_thing = [reviews];
// Promise.all(json_thing).then((final) => {
// console.log(final);
// });
// console.log(Reviews.ReviewsAPI.getReviews("ChIJdxxU1WeuEmsR11c4fswX-Io"));
// console.log("back to main");
// fetch(
// "https://maps.googleapis.com/maps/api/place/textsearch/json?query=restaurants%20in%20Sydney&key=AIzaSyAIhiPvfSCCmtoxJ4eFuCaWeW3onqe6Lkk"
// )
// .then((response) => response.json())
// .then((data) => listNamesIds(data.results));
const username = "tysu";
const password = "1234";
// fetch(`${server}/login/${username},${password}`)
// .then(res => res.json())
// .then(data => console.log(data));
// app.get("/")
app.use("/users", users);
app.use("/users", users);
app.use("/reviews", reviews);
app.use("/places", places);
app.get(`${server}/users/login/${username},${password}`, (req, res) => {
// res.send("Hello World");
console.log("hi");
console.log(req.json());
});
app.listen(port, () => console.log("listening on port " + port));