From 09f0436f986639f8e4e79f24376730679ae57431 Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Thu, 27 Aug 2020 13:25:44 +0200 Subject: [PATCH 01/32] add search functionality --- api/vinmonopolet.js | 0 api/wineinfo.js | 46 ++++++++++++++++++++++++++++++++++ src/api.js | 16 ++++++++++++ src/components/RequestWine.vue | 44 ++++++++++++++++++++++++++++++++ src/routes/vinlottisRouter.js | 6 +++++ 5 files changed, 112 insertions(+) create mode 100644 api/vinmonopolet.js create mode 100644 src/components/RequestWine.vue diff --git a/api/vinmonopolet.js b/api/vinmonopolet.js new file mode 100644 index 0000000..e69de29 diff --git a/api/wineinfo.js b/api/wineinfo.js index 237de19..8c444dd 100644 --- a/api/wineinfo.js +++ b/api/wineinfo.js @@ -9,6 +9,52 @@ router.use((req, res, next) => { next(); }); +const convertToOurWineObject = wine => { + console.log("traff her", wine) + return { + name: wine.basic.productShortName, + image: `https://bilder.vinmonopolet.no/cache/300x300-0/${wine.basic.productId}-1.jpg`, + rating: undefined, + price: wine.prices[0].salesPrice, + country: wine.origins.origin.country, + vivinoLink: undefined + } +} + +router.route("/wineinfo/search").get(async (req, res) => { + console.log("h") + console.log(req) + const {query} = req.query + let url = new URL(`https://apis.vinmonopolet.no/products/v0/details-normal?productShortNameContains=test&maxResults=5`) + url.searchParams.set('productShortNameContains', query) + + const vinmonopoletResponse = await fetch(url, { + headers: { + "Ocp-Apim-Subscription-Key": "" + } + }) + .then(resp => resp.json()) + + const winesConverted = vinmonopoletResponse.map(convertToOurWineObject) + console.log(winesConverted) + + if (vinmonopoletResponse.errors != null) { + return vinmonopoletResponse.errors.map(error => { + if (error.type == "UnknownProductError") { + return res.status(404).json({ + message: error.message + }) + } else { + return next() + } + }) + } + + res.send(winesConverted); +}); + + + router.route("/wineinfo/:ean").get(async (req, res) => { const vinmonopoletResponse = await fetch("https://app.vinmonopolet.no/vmpws/v2/vmp/products/barCodeSearch/" + req.params.ean) .then(resp => resp.json()) diff --git a/src/api.js b/src/api.js index eb6d3c2..395de2d 100644 --- a/src/api.js +++ b/src/api.js @@ -160,6 +160,21 @@ const barcodeToVinmonopolet = id => { }); }; +const searchForWine = searchString => { + const url = new URL("/api/wineinfo/search?query=" + searchString, BASE_URL); + + return fetch(url.href).then(async resp => { + if (!resp.ok) { + if (resp.status == 404) { + throw await resp.json(); + } + } else { + return resp.json(); + } + }); +}; + + const handleErrors = async resp => { if ([400, 409].includes(resp.status)) { throw await resp.json(); @@ -269,6 +284,7 @@ export { logWines, wineSchema, barcodeToVinmonopolet, + searchForWine, login, register, addAttendee, diff --git a/src/components/RequestWine.vue b/src/components/RequestWine.vue new file mode 100644 index 0000000..b1af2f3 --- /dev/null +++ b/src/components/RequestWine.vue @@ -0,0 +1,44 @@ + + + + + \ No newline at end of file diff --git a/src/routes/vinlottisRouter.js b/src/routes/vinlottisRouter.js index 32ae017..9a2e9cf 100644 --- a/src/routes/vinlottisRouter.js +++ b/src/routes/vinlottisRouter.js @@ -12,6 +12,8 @@ import WinnerPage from "@/components/WinnerPage"; import LotteryPage from "@/components/LotteryPage"; import HistoryPage from "@/components/HistoryPage"; +import RequestWine from "@/components/RequestWine"; + const routes = [ { path: "*", @@ -52,6 +54,10 @@ const routes = [ { path: "/history", component: HistoryPage + }, + { + path: "/request", + component: RequestWine } ]; From 15b84a9b18c3c90e20341e12a81771f8256ddaba Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Thu, 27 Aug 2020 15:15:43 +0200 Subject: [PATCH 02/32] add token and some styling --- .gitignore | 1 + api/wineinfo.js | 25 ++++++------ src/components/RequestWine.vue | 72 ++++++++++++++++++++++++++++++---- 3 files changed, 77 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 86fe51d..2a2c678 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ public/index.html public/sw/ config/env/lottery.config.js config/env/push.config.js +config/env/vinmonopolet.config.js # Logs logs diff --git a/api/wineinfo.js b/api/wineinfo.js index 8c444dd..1b4c7ff 100644 --- a/api/wineinfo.js +++ b/api/wineinfo.js @@ -2,6 +2,7 @@ const express = require("express"); const path = require("path"); const router = express.Router(); const fetch = require('node-fetch') +const config = require(path.join(__dirname + "/../config/env/vinmonopolet.config")); const mustBeAuthenticated = require(path.join(__dirname + "/../middleware/mustBeAuthenticated")) @@ -10,33 +11,31 @@ router.use((req, res, next) => { }); const convertToOurWineObject = wine => { - console.log("traff her", wine) - return { - name: wine.basic.productShortName, - image: `https://bilder.vinmonopolet.no/cache/300x300-0/${wine.basic.productId}-1.jpg`, - rating: undefined, - price: wine.prices[0].salesPrice, - country: wine.origins.origin.country, - vivinoLink: undefined + if(wine.basic.ageLimit === "18"){ + return { + name: wine.basic.productShortName, + image: `https://bilder.vinmonopolet.no/cache/300x300-0/${wine.basic.productId}-1.jpg`, + rating: undefined, + price: wine.prices[0].salesPrice, + country: wine.origins.origin.country, + vivinoLink: undefined + } } } router.route("/wineinfo/search").get(async (req, res) => { - console.log("h") - console.log(req) const {query} = req.query let url = new URL(`https://apis.vinmonopolet.no/products/v0/details-normal?productShortNameContains=test&maxResults=5`) url.searchParams.set('productShortNameContains', query) const vinmonopoletResponse = await fetch(url, { headers: { - "Ocp-Apim-Subscription-Key": "" + "Ocp-Apim-Subscription-Key": `${config.gatewayToken}` } }) .then(resp => resp.json()) - const winesConverted = vinmonopoletResponse.map(convertToOurWineObject) - console.log(winesConverted) + const winesConverted = vinmonopoletResponse.map(convertToOurWineObject).filter(Boolean) if (vinmonopoletResponse.errors != null) { return vinmonopoletResponse.errors.map(error => { diff --git a/src/components/RequestWine.vue b/src/components/RequestWine.vue index b1af2f3..d02c6f0 100644 --- a/src/components/RequestWine.vue +++ b/src/components/RequestWine.vue @@ -1,16 +1,30 @@ @@ -39,6 +53,48 @@ export default { } - \ No newline at end of file From f785a111d852244a0d199baf1e0fd7950a941d76 Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Thu, 27 Aug 2020 16:50:04 +0200 Subject: [PATCH 03/32] cleanup --- api/wineinfo.js | 4 +- src/components/RequestWine.vue | 93 +++++++++++++++++++++++++--------- src/styles/global.scss | 6 ++- 3 files changed, 75 insertions(+), 28 deletions(-) diff --git a/api/wineinfo.js b/api/wineinfo.js index 1b4c7ff..37afbf2 100644 --- a/api/wineinfo.js +++ b/api/wineinfo.js @@ -15,10 +15,10 @@ const convertToOurWineObject = wine => { return { name: wine.basic.productShortName, image: `https://bilder.vinmonopolet.no/cache/300x300-0/${wine.basic.productId}-1.jpg`, - rating: undefined, + rating: wine.basic.alcoholContent, price: wine.prices[0].salesPrice, country: wine.origins.origin.country, - vivinoLink: undefined + vivinoLink: "https://www.vinmonopolet.no/p/" + wine.basic.productId } } } diff --git a/src/components/RequestWine.vue b/src/components/RequestWine.vue index d02c6f0..75a189a 100644 --- a/src/components/RequestWine.vue +++ b/src/components/RequestWine.vue @@ -4,8 +4,10 @@ Foreslå en vin!
- - +
+ + +

{{ wine.name }}

(no name)

- {{ wine.price }} NOK - {{ wine.country }} +
+ {{ wine.rating }}% + {{ wine.price }} NOK + {{ wine.country }} +
- + Les mer på polet
+

+ Fant ingen viner med det navnet! +

@@ -40,14 +52,15 @@ export default { data() { return { searchString: undefined, - res: undefined, wines: undefined, } }, methods: { fetchWineFromVin(){ - searchForWine(this.searchString) - .then(res => this.wines = res) + if(this.searchString){ + searchForWine(this.searchString) + .then(res => this.wines = res) + } }, }, } @@ -61,6 +74,7 @@ export default { main{ margin: auto; width: 80%; + text-align: center; } input[type="text"] { @@ -69,32 +83,61 @@ input[type="text"] { border-radius: 4px; padding: 0.5rem 1rem; border: 1px solid black; - max-width: 200px; + max-width: 80%; +} + +.search-section{ + display: flex; + justify-content: space-around; + flex-flow: row; } .search-results-container{ display: flex; - border: 1px solid black; + padding: 3px; + border-radius: 1px; + box-shadow: 0px 0px 0px 1px rgba(0,0,0,0.3); + margin: 1rem 0; + justify-content: space-around; + flex-flow: row wrap; + align-items: stretch; + + + .wine-image { + height: 100px; + } + + .wine-placeholder { + height: 100px; + width: 70px; + } + + .wine-info{ + display: flex; + flex-direction: column; + .__details{ + display: flex; + flex-direction: column; + } + } + .wine-link { + color: #333333; + font-family: Arial; + text-decoration: none; + font-weight: bold; + border-bottom: 1px solid #ff5fff; + width: fit-content; + } .buttons{ - margin-left: auto; + display: flex; + align-items: center; order: 2; + justify-content: space-between; + width: 40%; + margin-right: 1rem; } } -.wine-image { - height: 100px; -} - -.wine-placeholder { - height: 100px; - width: 70px; -} - -.wine-info{ - display: flex; - flex-direction: column; -} - \ No newline at end of file diff --git a/src/styles/global.scss b/src/styles/global.scss index 57e3251..cc89a83 100644 --- a/src/styles/global.scss +++ b/src/styles/global.scss @@ -133,13 +133,17 @@ textarea { 0 16px 32px rgba(0, 0, 0, 0.07), 0 32px 64px rgba(0, 0, 0, 0.07); } - &:hover { + &:hover:not(:disabled) { transform: scale(1.02) translateZ(0); &::after { opacity: 1; } } + &:disabled{ + opacity: 0.25; + cursor: not-allowed; + } } .no-margin { From 7b7895728bdc835a3dd6c65d24f3343f986aea34 Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Fri, 28 Aug 2020 17:01:53 +0200 Subject: [PATCH 04/32] loko --- api/request.js | 60 ++++++++++++++++++++++++++++++++++ api/wineinfo.js | 14 ++++---- server.js | 2 ++ src/components/RequestWine.vue | 22 +++++++++++-- 4 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 api/request.js diff --git a/api/request.js b/api/request.js new file mode 100644 index 0000000..d2aca2b --- /dev/null +++ b/api/request.js @@ -0,0 +1,60 @@ +const express = require("express"); +const path = require("path"); +const router = express.Router(); +const fetch = require('node-fetch'); +const { send } = require("process"); +const RequestedWine = require(path.join( + __dirname + "/../schemas/RequestedWine" +)); +const Wine = require(path.join( + __dirname + "/../schemas/Wine" +)); + +router.use((req, res, next) => { + next(); +}); + + +router.route("/request").get(async (req, res) => { + const rWines = await RequestedWine.find({}).populate("wine") + return res.send(rWines) +}) + +router.route("/request").post(async (req, res) => { + const {wine} = req.body + console.log(wine) + + let thisWineIsLOKO = await Wine.findOne({id: wine.id}) + + if(thisWineIsLOKO == undefined){ + thisWineIsLOKO = new Wine({ + name: wine.name, + vivinoLink: wine.vivinoLink, + rating: null, + occurences: null, + image: wine.image, + id: wine.id + }); + await thisWineIsLOKO.save() + } + console.log(thisWineIsLOKO) + + let requestedWine = await RequestedWine.findOne({ "wineId": wine.id}) + + if(requestedWine == undefined){ + // console.log(localWine) + requestedWine = new RequestedWine({ + count: 1, + wineId: wine.id, + wine: thisWineIsLOKO + }) + } else { + requestedWine.count += 1; + } + await requestedWine.save() + + res.send(requestedWine); + +}); + +module.exports = router; diff --git a/api/wineinfo.js b/api/wineinfo.js index 37afbf2..053a68c 100644 --- a/api/wineinfo.js +++ b/api/wineinfo.js @@ -14,11 +14,13 @@ const convertToOurWineObject = wine => { if(wine.basic.ageLimit === "18"){ return { name: wine.basic.productShortName, - image: `https://bilder.vinmonopolet.no/cache/300x300-0/${wine.basic.productId}-1.jpg`, + vivinoLink: "https://www.vinmonopolet.no/p/" + wine.basic.productId, rating: wine.basic.alcoholContent, - price: wine.prices[0].salesPrice, - country: wine.origins.origin.country, - vivinoLink: "https://www.vinmonopolet.no/p/" + wine.basic.productId + occurences: 0, + id: wine.basic.productId, + image: `https://bilder.vinmonopolet.no/cache/300x300-0/${wine.basic.productId}-1.jpg`, + price: wine.prices[0].salesPrice.toString(), + country: wine.origins.origin.country } } } @@ -34,8 +36,8 @@ router.route("/wineinfo/search").get(async (req, res) => { } }) .then(resp => resp.json()) + .catch(err => console.error(err)) - const winesConverted = vinmonopoletResponse.map(convertToOurWineObject).filter(Boolean) if (vinmonopoletResponse.errors != null) { return vinmonopoletResponse.errors.map(error => { @@ -48,7 +50,7 @@ router.route("/wineinfo/search").get(async (req, res) => { } }) } - + const winesConverted = vinmonopoletResponse.map(convertToOurWineObject).filter(Boolean) res.send(winesConverted); }); diff --git a/server.js b/server.js index e0fef6f..8cd45e2 100644 --- a/server.js +++ b/server.js @@ -11,6 +11,7 @@ const retrieveApi = require(path.join(__dirname + "/api/retrieve")); const subscriptionApi = require(path.join(__dirname + "/api/subscriptions")); const loginApi = require(path.join(__dirname + "/api/login")); const wineinfoApi = require(path.join(__dirname + "/api/wineinfo")); +const requestApi = require(path.join(__dirname + "/api/request")); const virtualApi = require(path.join(__dirname + "/api/virtualLottery")); const virtualRegistrationApi = require(path.join( __dirname + "/api/virtualRegistration" @@ -94,6 +95,7 @@ app.use("/", loginApi); app.use("/api/", updateApi); app.use("/api/", retrieveApi); app.use("/api/", wineinfoApi); +app.use("/api/", requestApi); app.use("/api/", chatHistory); app.use("/api/lottery", lottery); app.use("/api/virtual/", virtualApi(io)); diff --git a/src/components/RequestWine.vue b/src/components/RequestWine.vue index 75a189a..edc217c 100644 --- a/src/components/RequestWine.vue +++ b/src/components/RequestWine.vue @@ -26,7 +26,7 @@
- + this.wines = res) } }, + request(wine){ + const options = { + body: JSON.stringify({ + wine: wine + }), + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + method: "post" + } + + fetch("http://localhost:30030/api/request", options) + .then(res => res.json()) + .then(console.log) + } }, } From aea808dae1959ec1e7e4f91c14c50650a77e343e Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Fri, 28 Aug 2020 17:20:37 +0200 Subject: [PATCH 05/32] =?UTF-8?q?=F0=9F=8D=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/wineinfo.js | 4 ++-- config/env/lottery.config.example.js | 5 +++-- schemas/RequestedWine.js | 13 +++++++++++++ 3 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 schemas/RequestedWine.js diff --git a/api/wineinfo.js b/api/wineinfo.js index 053a68c..d2cac75 100644 --- a/api/wineinfo.js +++ b/api/wineinfo.js @@ -2,7 +2,7 @@ const express = require("express"); const path = require("path"); const router = express.Router(); const fetch = require('node-fetch') -const config = require(path.join(__dirname + "/../config/env/vinmonopolet.config")); +const config = require(path.join(__dirname + "/../config/env/lottery.config")); const mustBeAuthenticated = require(path.join(__dirname + "/../middleware/mustBeAuthenticated")) @@ -32,7 +32,7 @@ router.route("/wineinfo/search").get(async (req, res) => { const vinmonopoletResponse = await fetch(url, { headers: { - "Ocp-Apim-Subscription-Key": `${config.gatewayToken}` + "Ocp-Apim-Subscription-Key": config.vinmonopoletToken } }) .then(resp => resp.json()) diff --git a/config/env/lottery.config.example.js b/config/env/lottery.config.example.js index 594b3d7..98b8d4d 100644 --- a/config/env/lottery.config.example.js +++ b/config/env/lottery.config.example.js @@ -6,5 +6,6 @@ module.exports = { date: 5, hours: 15, apiUrl: undefined, - gatewayToken: undefined -}; + gatewayToken: undefined, + vinmonopoletToken: undefined +}; \ No newline at end of file diff --git a/schemas/RequestedWine.js b/schemas/RequestedWine.js new file mode 100644 index 0000000..12c7257 --- /dev/null +++ b/schemas/RequestedWine.js @@ -0,0 +1,13 @@ +const mongoose = require("mongoose"); +const Schema = mongoose.Schema; + +const RequestedWine = new Schema({ + count: Number, + wineId: String, + wine: { + type: Schema.Types.ObjectId, + ref: "Wine" + } +}); + +module.exports = mongoose.model("RequestedWine", RequestedWine); From 543a7a6eb3aa300ebf89ae320898a85e5aa528ec Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Sun, 30 Aug 2020 17:27:03 +0200 Subject: [PATCH 06/32] some cleanup and css fix for mobile --- api/request.js | 3 --- api/wineinfo.js | 2 +- src/components/RequestWine.vue | 22 ++++++++++++++++++++-- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/api/request.js b/api/request.js index d2aca2b..53511c9 100644 --- a/api/request.js +++ b/api/request.js @@ -22,7 +22,6 @@ router.route("/request").get(async (req, res) => { router.route("/request").post(async (req, res) => { const {wine} = req.body - console.log(wine) let thisWineIsLOKO = await Wine.findOne({id: wine.id}) @@ -37,12 +36,10 @@ router.route("/request").post(async (req, res) => { }); await thisWineIsLOKO.save() } - console.log(thisWineIsLOKO) let requestedWine = await RequestedWine.findOne({ "wineId": wine.id}) if(requestedWine == undefined){ - // console.log(localWine) requestedWine = new RequestedWine({ count: 1, wineId: wine.id, diff --git a/api/wineinfo.js b/api/wineinfo.js index d2cac75..a5d0497 100644 --- a/api/wineinfo.js +++ b/api/wineinfo.js @@ -27,7 +27,7 @@ const convertToOurWineObject = wine => { router.route("/wineinfo/search").get(async (req, res) => { const {query} = req.query - let url = new URL(`https://apis.vinmonopolet.no/products/v0/details-normal?productShortNameContains=test&maxResults=5`) + let url = new URL(`https://apis.vinmonopolet.no/products/v0/details-normal?productShortNameContains=test&maxResults=15`) url.searchParams.set('productShortNameContains', query) const vinmonopoletResponse = await fetch(url, { diff --git a/src/components/RequestWine.vue b/src/components/RequestWine.vue index edc217c..055e6c9 100644 --- a/src/components/RequestWine.vue +++ b/src/components/RequestWine.vue @@ -26,7 +26,7 @@
- + res.json()) - .then(console.log) } }, } @@ -155,6 +154,25 @@ input[type="text"] { width: 40%; margin-right: 1rem; } + @include mobile { + display: flex; + flex-direction: column; + .wine-image { + height: 100px; + width: 50px; + align-self: center; + } + .buttons{ + display: flex; + flex-direction: column; + align-self: center; + margin: 1em; + .wine-link{ + margin-top: 1em; + } + } + + } } From b25e3a38f8bd446220928b56e698c50f6f639fd5 Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Mon, 31 Aug 2020 10:45:18 +0200 Subject: [PATCH 07/32] add modal component --- src/ui/Modal.vue | 100 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 src/ui/Modal.vue diff --git a/src/ui/Modal.vue b/src/ui/Modal.vue new file mode 100644 index 0000000..6d44ca6 --- /dev/null +++ b/src/ui/Modal.vue @@ -0,0 +1,100 @@ + + + + + \ No newline at end of file From c6a2bfe4b2621fb200c861a1afe1cadb67981db5 Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Mon, 31 Aug 2020 10:45:42 +0200 Subject: [PATCH 08/32] include modal on request specific wine --- src/components/RequestWine.vue | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/components/RequestWine.vue b/src/components/RequestWine.vue index 055e6c9..9325b41 100644 --- a/src/components/RequestWine.vue +++ b/src/components/RequestWine.vue @@ -3,6 +3,12 @@

Foreslå en vin!

+
@@ -44,15 +50,28 @@ + + \ No newline at end of file diff --git a/src/routes/vinlottisRouter.js b/src/routes/vinlottisRouter.js index 9a2e9cf..422b5a2 100644 --- a/src/routes/vinlottisRouter.js +++ b/src/routes/vinlottisRouter.js @@ -13,6 +13,7 @@ import LotteryPage from "@/components/LotteryPage"; import HistoryPage from "@/components/HistoryPage"; import RequestWine from "@/components/RequestWine"; +import AllRequestedWines from "@/components/AllRequestedWines"; const routes = [ { @@ -58,6 +59,10 @@ const routes = [ { path: "/request", component: RequestWine + }, + { + path: "/requested-wines", + component: AllRequestedWines } ]; From dd9edf160e423907531d2c00bde2f9078bc46f90 Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Mon, 31 Aug 2020 12:15:22 +0200 Subject: [PATCH 10/32] add endpoint for retrieving all requested wines --- api/retrieve.js | 8 ++++++++ api/vinmonopolet.js | 0 src/api.js | 7 +++++++ src/components/AllRequestedWines.vue | 19 ++++++++++++++++--- 4 files changed, 31 insertions(+), 3 deletions(-) delete mode 100644 api/vinmonopolet.js diff --git a/api/retrieve.js b/api/retrieve.js index c7577b8..9cbd64a 100644 --- a/api/retrieve.js +++ b/api/retrieve.js @@ -9,6 +9,7 @@ mongoose.connect("mongodb://localhost:27017/vinlottis", { const Purchase = require(path.join(__dirname + "/../schemas/Purchase")); const Wine = require(path.join(__dirname + "/../schemas/Wine")); const Highscore = require(path.join(__dirname + "/../schemas/Highscore")); +const RequestedWine = require(path.join(__dirname + "/../schemas/RequestedWine")); const PreLotteryWine = require(path.join( __dirname + "/../schemas/PreLotteryWine" )); @@ -103,6 +104,13 @@ router.route("/highscore/statistics").get(async (req, res) => { 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) => { const wines = await Wine.find(); diff --git a/api/vinmonopolet.js b/api/vinmonopolet.js deleted file mode 100644 index e69de29..0000000 diff --git a/src/api.js b/src/api.js index 395de2d..b549d22 100644 --- a/src/api.js +++ b/src/api.js @@ -24,6 +24,12 @@ const overallWineStatistics = () => { 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 url = new URL("/api/purchase/statistics/color", BASE_URL); @@ -285,6 +291,7 @@ export { wineSchema, barcodeToVinmonopolet, searchForWine, + allRequestedWines, login, register, addAttendee, diff --git a/src/components/AllRequestedWines.vue b/src/components/AllRequestedWines.vue index baa8bc8..8b84f61 100644 --- a/src/components/AllRequestedWines.vue +++ b/src/components/AllRequestedWines.vue @@ -1,14 +1,27 @@ From 1c9524485021f1924ac80aab77a0b8a012333457 Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Mon, 31 Aug 2020 16:45:19 +0200 Subject: [PATCH 11/32] interface on requested wines with sub-par css --- src/components/AllRequestedWines.vue | 24 +++++++--- src/ui/Modal.vue | 1 + src/ui/RequestedWineCard.vue | 72 ++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 7 deletions(-) create mode 100644 src/ui/RequestedWineCard.vue diff --git a/src/components/AllRequestedWines.vue b/src/components/AllRequestedWines.vue index 8b84f61..cabfb87 100644 --- a/src/components/AllRequestedWines.vue +++ b/src/components/AllRequestedWines.vue @@ -1,30 +1,40 @@ - \ No newline at end of file diff --git a/src/ui/Modal.vue b/src/ui/Modal.vue index 6d44ca6..0d0e8f8 100644 --- a/src/ui/Modal.vue +++ b/src/ui/Modal.vue @@ -97,4 +97,5 @@ export default { position: relative; padding: 20px 10px; } + \ No newline at end of file diff --git a/src/ui/RequestedWineCard.vue b/src/ui/RequestedWineCard.vue new file mode 100644 index 0000000..76b30fd --- /dev/null +++ b/src/ui/RequestedWineCard.vue @@ -0,0 +1,72 @@ + + + + + \ No newline at end of file From a5ae46f5c39b5497b66302f0fcb4c3f0cc50ab8e Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Tue, 1 Sep 2020 10:17:17 +0200 Subject: [PATCH 12/32] working delete requested wine if admin --- api/request.js | 7 +++++++ src/api.js | 16 ++++++++++++++++ src/components/AllRequestedWines.vue | 15 ++++++++++----- src/ui/RequestedWineCard.vue | 16 +++++++++++++++- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/api/request.js b/api/request.js index 53511c9..d318beb 100644 --- a/api/request.js +++ b/api/request.js @@ -9,11 +9,18 @@ const RequestedWine = require(path.join( const Wine = require(path.join( __dirname + "/../schemas/Wine" )); +const mustBeAuthenticated = require(path.join( + __dirname + "/../middleware/mustBeAuthenticated" +)); router.use((req, res, next) => { next(); }); +router.route("/request/").delete(mustBeAuthenticated, async (req, res) => { + await RequestedWine.deleteOne({wineId: req.body.id}) + res.json(true); +}) router.route("/request").get(async (req, res) => { const rWines = await RequestedWine.find({}).populate("wine") diff --git a/src/api.js b/src/api.js index b549d22..1d5bb7f 100644 --- a/src/api.js +++ b/src/api.js @@ -100,6 +100,21 @@ const winners = () => { return fetch(url.href).then(resp => resp.json()); }; +const deleteRequestedWine = wineToBeDeleted => { + console.log("when do i get here", wineToBeDeleted) + const url = new URL("api/request", BASE_URL); + + const options = { + headers: { + "Content-Type": "application/json" + }, + method: "DELETE", + body: JSON.stringify(wineToBeDeleted) + }; + + return fetch(url.href, options).then(resp => resp.json()) +} + const deleteWinners = () => { const url = new URL("/api/virtual/winners", BASE_URL); @@ -302,6 +317,7 @@ export { winnersSecure, deleteWinners, deleteAttendees, + deleteRequestedWine, getChatHistory, finishedDraw, getAmIWinner, diff --git a/src/components/AllRequestedWines.vue b/src/components/AllRequestedWines.vue index cabfb87..01033af 100644 --- a/src/components/AllRequestedWines.vue +++ b/src/components/AllRequestedWines.vue @@ -1,10 +1,10 @@ @@ -22,9 +22,14 @@ export default { canRequest: true } }, - async mounted() { - const wines = await allRequestedWines(); - this.wines = wines + methods: { + async refreshData(){ + const wines = await allRequestedWines() + this.wines = wines + } + }, + mounted() { + this.refreshData() } } diff --git a/src/ui/RequestedWineCard.vue b/src/ui/RequestedWineCard.vue index 76b30fd..3c85be0 100644 --- a/src/ui/RequestedWineCard.vue +++ b/src/ui/RequestedWineCard.vue @@ -19,11 +19,16 @@ class="wine-link" >Les mer på polet
+
From c38f5c88195c51572973e00172997afb74fcf1a8 Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Tue, 1 Sep 2020 10:44:54 +0200 Subject: [PATCH 13/32] some cleaning and empty wine list check --- src/api.js | 2 +- src/components/AllRequestedWines.vue | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/api.js b/src/api.js index 1d5bb7f..f08e3ed 100644 --- a/src/api.js +++ b/src/api.js @@ -101,7 +101,7 @@ const winners = () => { }; const deleteRequestedWine = wineToBeDeleted => { - console.log("when do i get here", wineToBeDeleted) + const url = new URL("api/request", BASE_URL); const options = { diff --git a/src/components/AllRequestedWines.vue b/src/components/AllRequestedWines.vue index 01033af..ffd8d6c 100644 --- a/src/components/AllRequestedWines.vue +++ b/src/components/AllRequestedWines.vue @@ -4,6 +4,7 @@ Alle foreslåtte viner
+

Ingen har foreslått noe enda!

@@ -35,6 +36,9 @@ export default { From e481b6a812c9fa7491ae91f6d8201730ca8a12af Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Wed, 2 Sep 2020 12:52:45 +0200 Subject: [PATCH 18/32] reworked header to be one component scaling on css properties --- src/Vinlottis.vue | 35 +++++++--- src/styles/banner.scss | 147 ++++++++++++++++++++++++++++++++++++++++ src/ui/Banner.vue | 121 ++++++++++++++++++--------------- src/ui/MobileBanner.vue | 108 ----------------------------- 4 files changed, 238 insertions(+), 173 deletions(-) create mode 100644 src/styles/banner.scss delete mode 100644 src/ui/MobileBanner.vue diff --git a/src/Vinlottis.vue b/src/Vinlottis.vue index af8aea7..4a5c4c1 100644 --- a/src/Vinlottis.vue +++ b/src/Vinlottis.vue @@ -1,7 +1,6 @@ From 6d26da181715184672466fc95921344ffe13c7e2 Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Mon, 7 Sep 2020 13:15:10 +0200 Subject: [PATCH 22/32] resolve first batch of comments --- .gitignore | 1 - api/retrieve.js | 1 - src/components/AllRequestedWines.vue | 11 ++++++----- src/ui/RequestedWineCard.vue | 8 ++++---- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 2a2c678..86fe51d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ public/index.html public/sw/ config/env/lottery.config.js config/env/push.config.js -config/env/vinmonopolet.config.js # Logs logs diff --git a/api/retrieve.js b/api/retrieve.js index ef9d7c9..8d36da6 100644 --- a/api/retrieve.js +++ b/api/retrieve.js @@ -9,7 +9,6 @@ mongoose.connect("mongodb://localhost:27017/vinlottis", { const Purchase = require(path.join(__dirname + "/../schemas/Purchase")); const Wine = require(path.join(__dirname + "/../schemas/Wine")); const Highscore = require(path.join(__dirname + "/../schemas/Highscore")); -const RequestedWine = require(path.join(__dirname + "/../schemas/RequestedWine")); const PreLotteryWine = require(path.join( __dirname + "/../schemas/PreLotteryWine" )); diff --git a/src/components/AllRequestedWines.vue b/src/components/AllRequestedWines.vue index 9022fc4..33e2dbd 100644 --- a/src/components/AllRequestedWines.vue +++ b/src/components/AllRequestedWines.vue @@ -4,8 +4,8 @@ Alle foreslåtte viner
-

Ingen har foreslått noe enda!

- +

Ingen har foreslått noe enda!

+
@@ -24,10 +24,11 @@ export default { } }, methods: { + filterOutDeletedWine(wine){ + this.wines = this.wines.filter(item => item.wine._id !== wine._id) + }, async refreshData(){ - this.wines = [] - const wines = await allRequestedWines() - this.wines = wines + this.wines = await allRequestedWines() || [] } }, mounted() { diff --git a/src/ui/RequestedWineCard.vue b/src/ui/RequestedWineCard.vue index 232431b..d29f52e 100644 --- a/src/ui/RequestedWineCard.vue +++ b/src/ui/RequestedWineCard.vue @@ -19,9 +19,9 @@ class="wine-link" >Les mer på polet
- + @@ -63,9 +63,9 @@ export default { if (window.confirm("Er du sikker på at du vil slette vinen?")) { let response = await deleteRequestedWine(wine); if (response) { - this.$emit('deletedOne'); + this.$emit('wineDeleted', wine); } else { - alert("Klarte ikke hente ut vinnere"); + alert("Klarte ikke slette vinen"); } } }, From ea278a489250ee00a1a321375f4624f24c319a66 Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Mon, 7 Sep 2020 14:50:40 +0200 Subject: [PATCH 23/32] remove console log --- api/request.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/api/request.js b/api/request.js index 23bceb7..f7ac11c 100644 --- a/api/request.js +++ b/api/request.js @@ -31,8 +31,6 @@ const getAllRequestedWines = async (req, res) => { const requestNewWine = async (req, res) => { const {wine} = req.body - - console.log(req.body) let thisWineIsLOKO = await Wine.findOne({id: wine.id}) From e060ff3aaa283659baa78954de225b274aee3629 Mon Sep 17 00:00:00 2001 From: Adrian Thompson Date: Mon, 7 Sep 2020 14:57:52 +0200 Subject: [PATCH 24/32] cleanup api use --- src/components/RequestWine.vue | 16 ++-------------- src/ui/RequestedWineCard.vue | 15 ++------------- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/src/components/RequestWine.vue b/src/components/RequestWine.vue index aaffdf3..58fbd32 100644 --- a/src/components/RequestWine.vue +++ b/src/components/RequestWine.vue @@ -48,7 +48,7 @@