server v1.0.0

This commit is contained in:
2020-09-16 17:34:24 +02:00
parent a5232e7257
commit 27552e5eb0
13 changed files with 187 additions and 150 deletions

View File

@@ -1,8 +1,7 @@
import express from "express";
import * as services from "../services/services.js";
import Restaurant from "../models/restaurant.js";
import sanitizer from "string-sanitizer";
import restaurant from "../models/restaurant.js";
import { handleError } from "../services/services.js";
var router = express.Router();
@@ -18,9 +17,10 @@ router.get("/", (req, res) => {
$and: [
{ $or: [{ city: { $regex: regex } }, { name: { $regex: regex } }] },
{ hidden: false },
{ subscriptionActive: true },
],
},
"_id name city imgUrl workingHours description tags phone hidden",
"_id name city imgUrl workingHours description tags location links",
(err, results) => {
if (err) {
res.sendStatus(500);
@@ -36,6 +36,24 @@ router.get("/", (req, res) => {
}
});
// SEARCH RESTAURANTS BY LOCATION
router.get("/location", async (req, res) => {
try {
const location = {
coordinates: [req.query.lon, req.query.lat],
type: "Point",
};
const radius = parseInt(req.query.radius) * 1000;
const results = await Restaurant.find({
location: { $near: { $maxDistance: radius, $geometry: location } },
});
res.send(results);
} catch (error) {
handleError(error, res);
}
});
// AUTOCOMPLETE
router.get("/autocomplete/", (req, res) => {