-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from CMU-17-356/login
added backend adapter functions and user routes for user login
- Loading branch information
Showing
9 changed files
with
127 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
// This file used for importing all routes at once | ||
|
||
export { TaskRoutes } from './task'; | ||
|
||
export { UserRoutes } from './user'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import express from "express"; | ||
import { User } from '../models/user'; | ||
|
||
const router = express.Router(); | ||
|
||
// GET all Users | ||
router.get("/", (req, res) => { | ||
User.find({}, (err: any, result: any) => { | ||
if (err) { | ||
res.json(err); | ||
} else { | ||
res.json(result); | ||
} | ||
}); | ||
}); | ||
|
||
// GET a single User | ||
router.get("/:username", (req, res) => { | ||
User.find({ username: req.params.username}, (err: any, result: any) => { | ||
if (err) { | ||
res.json(err); | ||
} else { | ||
res.json(result); | ||
} | ||
}); | ||
}); | ||
|
||
// CREATE a new User | ||
router.post("/", async (req, res) => { | ||
console.log('post request') | ||
const user = req.body; | ||
const newUser = new User(user); | ||
await newUser.save(); | ||
|
||
res.json(newUser); | ||
}); | ||
|
||
|
||
// DELETE a User | ||
router.delete("/:username", async (req, res) => { | ||
User.findOneAndDelete({ username: req.params.username }, (err: any, result: any) => { | ||
if (err) { | ||
res.json(err); | ||
} else { | ||
res.json(result); | ||
} | ||
}); | ||
}); | ||
|
||
export const UserRoutes = router |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters