working delete requested wine if admin
This commit is contained in:
@@ -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
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
|
||||||
</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" />
|
||||||
</section>
|
</section>
|
||||||
</main>
|
</main>
|
||||||
</template>
|
</template>
|
||||||
@@ -22,9 +22,14 @@ export default {
|
|||||||
canRequest: true
|
canRequest: true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async mounted() {
|
methods: {
|
||||||
const wines = await allRequestedWines();
|
async refreshData(){
|
||||||
this.wines = wines
|
const wines = await allRequestedWines()
|
||||||
|
this.wines = wines
|
||||||
|
}
|
||||||
|
},
|
||||||
|
mounted() {
|
||||||
|
this.refreshData()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -19,11 +19,16 @@
|
|||||||
class="wine-link"
|
class="wine-link"
|
||||||
>Les mer på polet</a>
|
>Les mer på polet</a>
|
||||||
</section>
|
</section>
|
||||||
|
<button @click="deleteWine(wine)">
|
||||||
|
Slett vinen
|
||||||
|
</button>
|
||||||
</section>
|
</section>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { deleteRequestedWine } from "@/api";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data(){
|
data(){
|
||||||
return {
|
return {
|
||||||
@@ -40,7 +45,6 @@ export default {
|
|||||||
methods: {
|
methods: {
|
||||||
request(wine){
|
request(wine){
|
||||||
this.locallyRequested = true
|
this.locallyRequested = true
|
||||||
// wine.requested = true
|
|
||||||
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 {
|
|||||||
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) {
|
||||||
|
if (window.confirm("Er du sikker på at du vil slette vinen?")) {
|
||||||
|
let response = await deleteRequestedWine(wine);
|
||||||
|
if (response) {
|
||||||
|
this.$emit('deletedOne');
|
||||||
|
} else {
|
||||||
|
alert("Klarte ikke hente ut vinnere");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user