add endpoint for retrieving all requested wines

This commit is contained in:
Adrian Thompson
2020-08-31 12:15:22 +02:00
parent d67c1e77bd
commit dd9edf160e
4 changed files with 31 additions and 3 deletions

View File

@@ -9,6 +9,7 @@ mongoose.connect("mongodb://localhost:27017/vinlottis", {
const Purchase = require(path.join(__dirname + "/../schemas/Purchase")); const Purchase = require(path.join(__dirname + "/../schemas/Purchase"));
const Wine = require(path.join(__dirname + "/../schemas/Wine")); const Wine = require(path.join(__dirname + "/../schemas/Wine"));
const Highscore = require(path.join(__dirname + "/../schemas/Highscore")); const Highscore = require(path.join(__dirname + "/../schemas/Highscore"));
const RequestedWine = require(path.join(__dirname + "/../schemas/RequestedWine"));
const PreLotteryWine = require(path.join( const PreLotteryWine = require(path.join(
__dirname + "/../schemas/PreLotteryWine" __dirname + "/../schemas/PreLotteryWine"
)); ));
@@ -103,6 +104,13 @@ router.route("/highscore/statistics").get(async (req, res) => {
res.json(highscore); res.json(highscore);
}); });
router.route("/wines/all-requested-wines").get(async (req, res) => {
const allWines = await RequestedWine.find({}).populate("wine");
res.json(allWines);
});
router.route("/wines/statistics").get(async (req, res) => { router.route("/wines/statistics").get(async (req, res) => {
const wines = await Wine.find(); const wines = await Wine.find();

View File

View File

@@ -24,6 +24,12 @@ const overallWineStatistics = () => {
return fetch(url.href).then(resp => resp.json()); return fetch(url.href).then(resp => resp.json());
}; };
const allRequestedWines = () => {
const url = new URL("/api/wines/all-requested-wines", BASE_URL);
return fetch(url.href).then(resp => resp.json());
};
const chartWinsByColor = () => { const chartWinsByColor = () => {
const url = new URL("/api/purchase/statistics/color", BASE_URL); const url = new URL("/api/purchase/statistics/color", BASE_URL);
@@ -285,6 +291,7 @@ export {
wineSchema, wineSchema,
barcodeToVinmonopolet, barcodeToVinmonopolet,
searchForWine, searchForWine,
allRequestedWines,
login, login,
register, register,
addAttendee, addAttendee,

View File

@@ -1,14 +1,27 @@
<template> <template>
<main> <main>
<p> <h1>
Alle viner Alle viner
</p> </h1>
<section>
{{this.wines}}
</section>
</main> </main>
</template> </template>
<script> <script>
export default { import { allRequestedWines } from "@/api";
export default {
data(){
return{
wines: undefined
}
},
async mounted() {
const wines = await allRequestedWines();
this.wines = wines
}
} }
</script> </script>