fix conflicts and rework routes

This commit is contained in:
Adrian Thompson
2020-09-07 14:49:24 +02:00
27 changed files with 6208 additions and 4055 deletions

View File

@@ -1,3 +1,5 @@
import fetch from "node-fetch";
const BASE_URL = __APIURL__ || window.location.origin;
const statistics = () => {
@@ -48,8 +50,22 @@ const prelottery = () => {
return fetch(url.href).then(resp => resp.json());
};
const log = sendObject => {
const url = new URL("/api/log", BASE_URL);
const sendLottery = sendObject => {
const url = new URL("/api/lottery", BASE_URL);
const options = {
headers: {
"Content-Type": "application/json"
},
method: "POST",
body: JSON.stringify(sendObject)
};
return fetch(url.href, options).then(resp => resp.json());
};
const sendLotteryWinners = sendObject => {
const url = new URL("/api/lottery/winners", BASE_URL);
const options = {
headers: {
@@ -63,7 +79,7 @@ const log = sendObject => {
};
const addAttendee = sendObject => {
const url = new URL("/api/virtual/attendee", BASE_URL);
const url = new URL("/api/virtual/attendee/add", BASE_URL);
const options = {
headers: {
@@ -77,32 +93,32 @@ const addAttendee = sendObject => {
};
const getVirtualWinner = () => {
const url = new URL("/api/virtual/winner", BASE_URL);
const url = new URL("/api/virtual/winner/draw", BASE_URL);
return fetch(url.href).then(resp => resp.json());
};
const attendeesSecure = () => {
const url = new URL("/api/virtual/attendees/secure", BASE_URL);
const url = new URL("/api/virtual/attendee/all/secure", BASE_URL);
return fetch(url.href).then(resp => resp.json());
};
const winnersSecure = () => {
const url = new URL("/api/virtual/winners/secure", BASE_URL);
const url = new URL("/api/virtual/winner/all/secure", BASE_URL);
return fetch(url.href).then(resp => resp.json());
};
const winners = () => {
const url = new URL("/api/virtual/winners", BASE_URL);
const url = new URL("/api/virtual/winner/all", BASE_URL);
return fetch(url.href).then(resp => resp.json());
};
const deleteRequestedWine = wineToBeDeleted => {
const url = new URL("api/request", BASE_URL);
const url = new URL("api/request/"+ wineToBeDeleted._id, BASE_URL);
const options = {
headers: {
@@ -116,7 +132,7 @@ const deleteRequestedWine = wineToBeDeleted => {
}
const deleteWinners = () => {
const url = new URL("/api/virtual/winners", BASE_URL);
const url = new URL("/api/virtual/winner/all", BASE_URL);
const options = {
headers: {
@@ -129,7 +145,7 @@ const deleteWinners = () => {
};
const deleteAttendees = () => {
const url = new URL("/api/virtual/attendees", BASE_URL);
const url = new URL("/api/virtual/attendee/all", BASE_URL);
const options = {
headers: {
@@ -142,11 +158,28 @@ const deleteAttendees = () => {
};
const attendees = () => {
const url = new URL("/api/virtual/attendees", BASE_URL);
const url = new URL("/api/virtual/attendee/all", BASE_URL);
return fetch(url.href).then(resp => resp.json());
};
const requestNewWine = (wine) => {
const options = {
body: JSON.stringify({
wine: wine
}),
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
method: "post"
}
const url = new URL("/api/request/new-wine", BASE_URL)
return fetch(url.href, options).then(resp => resp.json())
}
const logWines = wines => {
const url = new URL("/api/log/wines", BASE_URL);
@@ -162,7 +195,7 @@ const logWines = wines => {
};
const wineSchema = () => {
const url = new URL("/api/log/schema", BASE_URL);
const url = new URL("/api/wineinfo/schema", BASE_URL);
return fetch(url.href).then(resp => resp.json());
};
@@ -253,17 +286,20 @@ const getChatHistory = (skip = null, take = null) => {
const finishedDraw = () => {
const url = new URL("/api/virtual/finish", BASE_URL);
const options = {
method: 'POST'
}
return fetch(url.href).then(resp => resp.json());
return fetch(url.href, options).then(resp => resp.json());
};
const getAmIWinner = id => {
const url = new URL(`/api/virtual-registration/${id}`, BASE_URL);
const url = new URL(`/api/winner/${id}`, BASE_URL);
return fetch(url.href).then(resp => resp.json());
};
const postWineChosen = (id, wineName) => {
const url = new URL(`/api/virtual-registration/${id}`, BASE_URL);
const url = new URL(`/api/winner/${id}`, BASE_URL);
const options = {
headers: {
"Content-Type": "application/json"
@@ -301,11 +337,13 @@ export {
chartWinsByColor,
chartPurchaseByColor,
prelottery,
log,
sendLottery,
sendLotteryWinners,
logWines,
wineSchema,
barcodeToVinmonopolet,
searchForWine,
requestNewWine,
allRequestedWines,
login,
register,