WIP Functionality to request wines for next lottery #24
@@ -9,11 +9,18 @@ const RequestedWine = require(path.join(
|
|||||||
const Wine = require(path.join(
|
const Wine = require(path.join(
|
||||||
__dirname + "/../schemas/Wine"
|
__dirname + "/../schemas/Wine"
|
||||||
));
|
));
|
||||||
|
const mustBeAuthenticated = require(path.join(
|
||||||
|
__dirname + "/../middleware/mustBeAuthenticated"
|
||||||
|
));
|
||||||
|
|
||||||
router.use((req, res, next) => {
|
router.use((req, res, next) => {
|
||||||
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) => {
|
router.route("/request").get(async (req, res) => {
|
||||||
const rWines = await RequestedWine.find({}).populate("wine")
|
const rWines = await RequestedWine.find({}).populate("wine")
|
||||||
|
|||||||
16
src/api.js
@@ -100,6 +100,21 @@ const winners = () => {
|
|||||||
return fetch(url.href).then(resp => resp.json());
|
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 deleteWinners = () => {
|
||||||
const url = new URL("/api/virtual/winners", BASE_URL);
|
const url = new URL("/api/virtual/winners", BASE_URL);
|
||||||
|
|
||||||
@@ -302,6 +317,7 @@ export {
|
|||||||
winnersSecure,
|
winnersSecure,
|
||||||
deleteWinners,
|
deleteWinners,
|
||||||
deleteAttendees,
|
deleteAttendees,
|
||||||
|
deleteRequestedWine,
|
||||||
getChatHistory,
|
getChatHistory,
|
||||||
finishedDraw,
|
finishedDraw,
|
||||||
getAmIWinner,
|
getAmIWinner,
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
|
|
|||||||
<template>
|
<template>
|
||||||
<main>
|
<main>
|
||||||
<h1>
|
<h1>
|
||||||
Alle viner foreslåtte viner
|
Alle foreslåtte viner
|
||||||
|
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
|
|||||||
</h1>
|
</h1>
|
||||||
<section class="requested-wines-container">
|
<section class="requested-wines-container">
|
||||||
<RequestedWineCard v-for="requestedEl in wines" :key="requestedEl.id" :requestedElement="requestedEl" />
|
<RequestedWineCard v-for="requestedEl in wines" :key="requestedEl.id" :requestedElement="requestedEl" @deletedOne="refreshData" />
|
||||||
|
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
|
|||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
@@ -22,9 +22,14 @@ export default {
|
|||||||
|
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
fixed fixed
|
|||||||
canRequest: true
|
canRequest: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
methods: {
|
||||||
|
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
|
|||||||
const wines = await allRequestedWines();
|
async refreshData(){
|
||||||
|
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
|
|||||||
this.wines = wines
|
const wines = await allRequestedWines()
|
||||||
|
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
|
|||||||
|
this.wines = wines
|
||||||
|
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
|
|||||||
|
}
|
||||||
|
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
|
|||||||
|
},
|
||||||
|
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
|
|||||||
|
mounted() {
|
||||||
|
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
|
|||||||
|
this.refreshData()
|
||||||
|
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
|
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
This is in the template which is scoped to This is in the template which is scoped to `this` so we can write: `wines == undefined`. Also the length of a list will not be less that zero so change check to be `wines.length == 0`.
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Shorthand would be Shorthand would be `this.wines = await allRequestedWines() || [];`
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
Could the item deleted be sent up here and we filter it away instead of making a new request? Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed fixed
fixed fixed
fixed fixed
fixed fixed
fixed fixed
fixed fixed
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
```suggestion
[this.wines, this.isAdmin] = await allRequestedWines() || [[], false]
```
fixed fixed
fixed fixed
|
|||||||
@@ -19,11 +19,16 @@
|
|||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
Vinnere ? Vinnere ?
fixed fixed
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
class="wine-link"
|
class="wine-link"
|
||||||
>Les mer på polet</a>
|
>Les mer på polet</a>
|
||||||
</section>
|
</section>
|
||||||
|
<button @click="deleteWine(wine)">
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
|
Slett vinen
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
|
</button>
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { deleteRequestedWine } from "@/api";
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
|
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
export default {
|
export default {
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
@@ -40,7 +45,6 @@ export default {
|
|||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
Vinnere ? Vinnere ?
fixed fixed
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
methods: {
|
methods: {
|
||||||
request(wine){
|
request(wine){
|
||||||
this.locallyRequested = true
|
this.locallyRequested = true
|
||||||
// wine.requested = true
|
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
this.requestedElement.count = this.requestedElement.count +1
|
this.requestedElement.count = this.requestedElement.count +1
|
||||||
const options = {
|
const options = {
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
@@ -55,6 +59,16 @@ export default {
|
|||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
Vinnere ? Vinnere ?
fixed fixed
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
fetch("http://localhost:30030/api/request", options)
|
fetch("http://localhost:30030/api/request", options)
|
||||||
.then(res => res.json())
|
.then(res => res.json())
|
||||||
},
|
},
|
||||||
|
async deleteWine(wine) {
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
|
if (window.confirm("Er du sikker på at du vil slette vinen?")) {
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
|
let response = await deleteRequestedWine(wine);
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
|
if (response) {
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
|
this.$emit('deletedOne');
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
|
} else {
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
|
alert("Klarte ikke hente ut vinnere");
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
|
}
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
|
}
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
|
},
|
||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
|
Rename too Rename too `wineDeleted` and emit the wine element.
Rename too Rename too `wineDeleted` and emit the wine element.
Vinnere ? Vinnere ?
Vinnere ? Vinnere ?
fixed fixed
fixed fixed
🤷♂️ fixed 🤷♂️ fixed
🤷♂️ fixed 🤷♂️ fixed
|
|||||||
This is in the template which is scoped to
thisso we can write:wines == undefined. Also the length of a list will not be less that zero so change check to bewines.length == 0.This is in the template which is scoped to
thisso we can write:wines == undefined. Also the length of a list will not be less that zero so change check to bewines.length == 0.Shorthand would be
this.wines = await allRequestedWines() || [];Shorthand would be
this.wines = await allRequestedWines() || [];Could the item deleted be sent up here and we filter it away instead of making a new request?
Could the item deleted be sent up here and we filter it away instead of making a new request?
fixed
fixed
fixed
fixed
fixed
fixed
fixed
fixed