{"size": 754, "ext": "js", "max_stars_repo_path": "routes/bots/search.js", "max_stars_repo_name": "BruhFish/botlist.github.io", "max_stars_repo_stars_event_min_datetime": "2020-11-07T17:58:26.000Z", "max_stars_repo_stars_event_max_datetime": "2021-10-16T14:14:26.000Z", "max_issues_repo_path": "routes/bots/search.js", "max_issues_repo_name": "BruhFish/botlist.github.io", "max_issues_repo_issues_event_min_datetime": "2021-09-02T14:29:30.000Z", "max_issues_repo_issues_event_max_datetime": "2022-01-22T13:23:20.000Z", "max_forks_repo_path": "routes/bots/search.js", "max_forks_repo_name": "BruhFish/botlist.github.io", "max_forks_repo_forks_event_min_datetime": "2020-09-04T01:35:01.000Z", "max_forks_repo_forks_event_max_datetime": "2021-07-07T02:09:38.000Z"}
{"max_stars_count": 4, "max_issues_count": 2, "max_forks_count": 14, "avg_line_length": 30.16, "max_line_length": 77, "alphanum_fraction": 0.5981432361}
const { Router } = require("express");
const Bots = require("../../models/bots");
const getList = require('../../utils/getList.js')

const route = Router();

route.get("/", async (req, res, next) => {
    let search = req.query.q;
    if (!search) search = "";
    search = search.toLowerCase();
    let bots = await getList();
    let found = bots.filter(bot => {
        if (bot.username.toLowerCase().includes(search)) return true;
        else if (bot.description.toLowerCase().includes(search)) return true;
        else return false;
    });
    if (!found) return res.send({ error: "No bots found for this search" });
    let data = {
        cards: found,
        search: search
    };
    res.render("search", data);
});

module.exports = route;