diff --git a/app.js b/app.js index 392eeda..153bbc7 100644 --- a/app.js +++ b/app.js @@ -14,12 +14,12 @@ mongoose.connect( const userSchema = new mongoose.Schema({ githubId: String, - profile: Object /* + profile: Object, /* { description: something // will check if exists, if not use github } */ - + handle: String }); const User = mongoose.model("User", userSchema); @@ -47,10 +47,6 @@ app.get("/", (req, res) => { res.render("home"); }); -app.get("/gh-username-search", (req, res) => { - res.render("pages/gh-username-search"); -}); - app.get("/profile", (req, res) => { if (!req.session.user) { return res.render("pages/login", { client_id: process.env.GITHUB_CLIENT_ID }); @@ -120,7 +116,13 @@ async function githubOAuthLogin(req, res) { } function createGithubOAuthUser(githubId, req, res) { - const user = new User({ githubId: githubId }); + const user = new User({ + githubId: githubId, + handle: req.session.user.login, + profile: { + description: req.session.user.bio + } + }); user.save().then((result) => { res.render("pages/welcome", { userData: req.session.user }); }); @@ -176,7 +178,28 @@ app.post("/edit/description", (req, res) => { }); }); +// Search +app.get("/search/user/:username", (req, res) => { + const username = req.params.username; + const results = 15; + User.find({ handle: { $regex: "^" + username } }) + .then((users) => {// should only send name and descr + res.json({ users: users.slice(0, results) }); + }) + .catch((err) => { + console.log(err); + }); +}); + // Connect app app.listen(PORT, () => { console.log("Server is running on port " + PORT); }); + + +// add new filed to existing schema members - remember to add to schema as well! +// User.updateMany( +// { handle: { $exists: false } }, +// { $set: { handle: "hnasheralneam" } }, +// { multi: true } +// ).then((oth) => { console.log(oth); }).catch((err) => { console.error("err-", err); }); \ No newline at end of file diff --git a/public/home.ejs b/public/home.ejs index 76c7303..32dd0fb 100644 --- a/public/home.ejs +++ b/public/home.ejs @@ -34,20 +34,13 @@ FetchCV, you can show off all your projects and achievements in one place!

+

Pro tip: you can search people by GitHub username, even if they don't have an account!


Get started!

- - -
- search -

GitHub username search

-
-
- - - - - - - - - GitHub Username Search | FetchCV - -<%- include("../partials/navbar.ejs") %> - -
- -
- -
- - person_search -
-
-
- - - diff --git a/public/pages/github-profile.ejs b/public/pages/github-profile.ejs index 704fb9b..2948a40 100644 --- a/public/pages/github-profile.ejs +++ b/public/pages/github-profile.ejs @@ -14,21 +14,10 @@ <%- include("../partials/navbar.ejs") %>
- -
- -
- - person_search -
-
- -
- -