Register page now uses api functions and can scan from vinmonopolet qr codes. Re-did formatting and styling on page.

This commit is contained in:
2020-03-10 00:17:32 +01:00
parent 72d67d862d
commit 43bf312007
5 changed files with 834 additions and 378 deletions

31
api/wineinfo.js Normal file
View File

@@ -0,0 +1,31 @@
const express = require("express");
const path = require("path");
const router = express.Router();
const fetch = require('node-fetch')
const mustBeAuthenticated = require(path.join(__dirname + "/../middleware/mustBeAuthenticated"))
router.use((req, res, next) => {
next();
});
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())
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(vinmonopoletResponse);
});
module.exports = router;