text: const axios = require("axios");
  const Dev = require("../models/Dev");
  
  const { findConnections, sendMessage } = require("../websocket");
  const parseStringAsArray = require("../utils/parseStringAsArray");
  
  module.exports = {
    async index(request, response) {
      const devs = await Dev.find();
  
      return response.json(devs);
    },
  
    async store(request, response) {
      const { github_username, techs, latitude, longitude } = request.body;
  
      let dev = await Dev.findOne({ github_username });
  
      if (!dev) {
        const githubResponse = await axios.get(
          `https://api.github.com/users/${github_username}`
        );
  
        const { name, avatar_url, bio } = githubResponse.data;
  
        const techsArray = parseStringAsArray(techs);
  
        const location = {
          type: "Point",
          coordinates: [longitude, latitude]
        };
  
        dev = await Dev.create({
          github_username,
          name,
          avatar_url,
          bio,
          techs: techsArray,
          location
        });
  
        // Filtrar conexões do socket
        const sendSocketMessageTo = findConnections(
          { latitude, longitude },
          techsArray
        );
  
        sendMessage(sendSocketMessageTo, "new-dev", dev);
      }
  
      return response.json(dev);
    }
  };
  