'Response not reflecting changes
I am experiencing some really weird behavior.The app was working fine and then even when i change the room id nothing changes in response . i even tried to remove app.get() method and call that route /api/availability, the response still pops up
app.get("/api/availability", (req, res) => {
res.json({ availability : availableroomsArray});});
No matter what I call , I get the same old response , changing the route to /api/available instead of /api/availability will show the same response in /api/availability.
this is my code :
var availableroomsArray = [];
var arrayAll = [];
var rooms =[];
var roomIds=[9748,7264,59038,110158,42714]
var obj = {};
const start = async function() {
// GET THE ROOMS
const body = {propId: "3578",
roomId: true};
const response =await fetch('https://api.beds24.com/json/getDescriptions', {
method: 'post',
body: JSON.stringify(body),
headers: {'Content-Type': 'application/json'}
});
const data = await response.json();
for (let i in roomIds) {
arrayAll.push(data["properties"]["rooms"][roomIds[i]]);
app.get("/api/rooms", (req, res) => {
res.json({ rooms: arrayAll});});
}
var from=await dateFormat(Date.now(), "yyyymmdd");
console.log("aa"+from);
var to=await dateFormat(new Date(new Date().setFullYear(new Date().getFullYear() + 1)), "yyyymmdd");
console.log("aa"+to);
//GET ROOM'S AVAILABILITY
for (let i in roomIds) {
const AvailBody = {"authentication": {
"apiKey": "privatekey",
"propKey": "privatekey"
},
"from": from, // datenow w format
"to": to,
"roomId": roomIds[i]
};
const AvailResponse =await fetch('https://api.beds24.com/json/getRoomDates', {
method: 'post',
body: JSON.stringify(AvailBody),
headers: {'Content-Type': 'application/json'}
});
var indicateur = roomIds[i]
const Availabilitydata = await AvailResponse.json();
obj[roomIds[i]] = Availabilitydata;
}
availableroomsArray.push(obj);
app.post("/api/availability", (req, res) => {
res.json({ availability : availableroomsArray});});
}
Solution 1:[1]
I was running the wrong project and editing another , they do have the same name.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Charfeddine Mohamed Ali |
