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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,5 @@ dmypy.json

# Pyre type checker
.pyre/

node_modules
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ app.post("/login", (req, res) => {
// Generate JWT access token
let accessToken = jwt.sign({
data: password
}, 'access', { expiresIn: 60 * 60 });
}, 'access', { expiresIn: 60 });

// Store access token and username in session
req.session.authorization = {
Expand Down Expand Up @@ -111,4 +111,4 @@ const PORT =5000;

app.use("/friends", routes);

app.listen(PORT,()=>console.log("Server is running"));
app.listen(PORT,()=>console.log("Server is running"));
198 changes: 198 additions & 0 deletions package-lock.json

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

67 changes: 51 additions & 16 deletions router/friends.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,37 +11,72 @@ let friends = {

// GET request: Retrieve all friends
router.get("/",(req,res)=>{
// Send JSON response with formatted friends data
res.send(JSON.stringify(friends,null,4));

// Update the code here

res.send("Yet to be implemented")//This line is to be replaced with actual return value
});

// 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
router.get('/:email', function(req, res) {
// Retrieve the email parameter from the request URL and send the corresponding friend's details
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
router.post("/", function(req, res) {
// Check if email is provided in the request body
if (req.body.email) {
// Create or update friend's details based on provided email
friends[req.body.email] = {
"firstName": req.body.firstName,
// Add similarly for lastName
// Add similarly for DOB
};
}
// Send response indicating user addition
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
});
router.put("/:email", function(req, res) {
// Extract email parameter from request URL
const email = req.params.email;
let friend = friends[email]; // Retrieve friend object associated with email

if (friend) { // Check if friend exists
let DOB = req.body.DOB;
// Add similarly for firstName
// Add similarly for lastName

// Update DOB if provided in request body
if (DOB) {
friend["DOB"] = DOB;
}
// Add similarly for firstName
// Add similarly for lastName

friends[email] = friend; // Update friend details in 'friends' object
res.send(`Friend with the email ${email} updated.`);
} else {
// Respond if friend with specified email is not found
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
// Extract email parameter from request URL
const email = req.params.email;

if (email) {
// Delete friend from 'friends' object based on provided email
delete friends[email];
}

// Send response confirming deletion of friend
res.send(`Friend with the email ${email} deleted.`);
});

module.exports=router;