Skip to content

Commit

Permalink
Merge pull request #12 from MRVDH/401s-and-totals
Browse files Browse the repository at this point in the history
Fixed 401's and added delivery totals
  • Loading branch information
MRVDH authored Jun 23, 2021
2 parents e528bd1 + 106479c commit 7f4ff42
Show file tree
Hide file tree
Showing 7 changed files with 16,040 additions and 154 deletions.
15,911 changes: 15,882 additions & 29 deletions client/package-lock.json

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
"dependencies": {
"axios": "^0.21.1",
"bootstrap-vue": "^2.21.2",
"core-js": "^3.10.1",
"mapbox-gl": "^2.2.0",
"vue": "^2.6.11",
"vue-router": "^3.5.1",
"core-js": "^3.15.1",
"mapbox-gl": "^2.3.1",
"vue": "^2.6.14",
"vue-router": "^3.5.2",
"vuex": "^3.6.2",
"vuex-persist": "^3.1.3"
},
Expand All @@ -26,9 +26,9 @@
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"sass": "^1.32.8",
"sass": "^1.35.1",
"sass-loader": "^10.1.1",
"vue-template-compiler": "^2.6.11"
"vue-template-compiler": "^2.6.14"
},
"eslintConfig": {
"root": true,
Expand Down
35 changes: 33 additions & 2 deletions client/src/components/routes/Settings.vue
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<h3>Bestellingen</h3>

<div v-if="user.completed_deliveries && deliveries && deliveries.length">
<p>Totaal {{ user.completed_deliveries }} afgeleverde bestellingen</p>
<p>Je hebt <strong>{{ amountOfDeliveries }}</strong> afgeleverde bestellingen voor totaal <strong>{{ totalDeliveryCosts }}</strong>.</p>

<div
v-for="delivery in deliveries"
Expand Down Expand Up @@ -111,7 +111,8 @@
</router-link>
</div>
</div>
<p v-else>Nog bestellingen geplaatst.</p>
<b-skeleton v-if="!deliveries" />
<p v-if="deliveries && !deliveries.length">Nog bestellingen geplaatst.</p>
</b-col>
</b-row>
</template>
Expand All @@ -134,6 +135,31 @@ export default {
computed: {
loggedIn () {
return this.$store.state.authKey;
},
amountOfDeliveries () {
if (this.deliveries?.length > 0) {
return this.deliveries.filter(x => x.delivery_time && new Date(x.delivery_time.end) < new Date()).length;
} else {
return 0;
}
},
totalDeliveryCosts () {
let totals = 0;
if (this.deliveries?.length > 0) {
for (let delivery of this.deliveries) {
let totalPrice = 0;
for (let order of delivery.orders) {
totalPrice += order.total_price / 100;
}
totals += totalPrice;
}
}
return new Intl.NumberFormat('nl-NL', { style: 'currency', currency: 'EUR' }).format(totals);
}
},
watch: {
Expand Down Expand Up @@ -253,4 +279,9 @@ button {
margin-top: -5px;
}
}
.b-skeleton-text {
width: 250px;
height: 24px;
}
</style>
11 changes: 11 additions & 0 deletions client/src/services/ApiService.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import axios from "axios";
import store from "@/store";
import { SET_AUTH_KEY } from '@/store/mutationTypes';

let baseURL = window.location.hostname === "localhost" ? "http://localhost:8081" : ("https://" + window.location.hostname);

Expand All @@ -15,6 +16,16 @@ httpInstance.interceptors.request.use((config) => {
return Promise.reject(error);
});

httpInstance.interceptors.response.use((response) => {
return response;
}, (error) => {
if (error.response.status === 401) {
store.dispatch(SET_AUTH_KEY, null);
}

return Promise.reject(error);
});

export default {
login (username, password) {
return httpInstance.post(`/api/login`, { username, password });
Expand Down
4 changes: 4 additions & 0 deletions middleware/picnicController.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ export default {
try {
await picnicClient.login(req.body.username, req.body.password);

if (req.body.username === process.env.ADMIN_USER_NAME) {
process.env.AUTH_KEY = picnicClient.authKey;
}

res.send({ authKey: picnicClient.authKey });
} catch {
res.sendStatus(500);
Expand Down
Loading

0 comments on commit 7f4ff42

Please sign in to comment.