Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
185 changes: 185 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 38 additions & 12 deletions router/friends.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,63 @@ let friends = {

// GET request: Retrieve all friends
router.get("/",(req,res)=>{

// Update the code here

res.send("Yet to be implemented")//This line is to be replaced with actual return value
res.send(JSON.stringify(friends,null,4));
});

// GET by specific ID request: Retrieve a single friend with email ID
router.get("/:email",(req,res)=>{
// Update the code here
res.send("Yet to be implemented")//This line is to be replaced with actual return value
const email = req.params.email;
res.send(friends[email])
});


// POST request: Add a new friend
router.post("/",(req,res)=>{
// Update the code here
res.send("Yet to be implemented")//This line is to be replaced with actual return value
if (req.body.email){
friends[req.body.email] = {
"firstName":req.body.firstName,
"lastName":req.body.lastName,
"DOB":req.body.DOB
}
}
res.send("The user" + (' ')+ (req.body.firstName) + " Has been added!");
});


// PUT request: Update the details of a friend with email id
router.put("/:email", (req, res) => {
// Update the code here
res.send("Yet to be implemented")//This line is to be replaced with actual return value
const email = req.params.email;
let friend = friends[email]
if (friend) { //Check is friend exists
let DOB = req.body.DOB;
let firstName = req.body.firstName;
let lastName = req.body.lastName;
//if DOB the DOB has been changed, update the DOB
if(DOB) {
friend["DOB"] = DOB
}
if(firstName) {
friend["firstName"] = firstName
}
if(lastName) {
friend["lastName"] = lastName
}
friends[email]=friend;
res.send(`Friend with the email ${email} updated.`);
}
else{
res.send("Unable to find friend!");
}
});


// DELETE request: Delete a friend by email id
router.delete("/:email", (req, res) => {
// Update the code here
res.send("Yet to be implemented")//This line is to be replaced with actual return value
const email = req.params.email;
if (email){
delete friends[email]
}
res.send(`Friend with the email ${email} deleted.`);
});

module.exports=router;