-
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.
Added backend friend form functionality.
- Loading branch information
1 parent
f03ad35
commit 5a4d1da
Showing
9 changed files
with
156 additions
and
69 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
"Mayfield", | ||
"PEMDAS", | ||
"roomies", | ||
"socialness", | ||
"Tolman", | ||
"Tyeire", | ||
"vunet", | ||
|
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,40 @@ | ||
const { | ||
addFriendsFormService, | ||
getAllFriendsFormsService, | ||
} = require("../services/friends.services"); | ||
|
||
const addFriendsForm = async (req, res) => { | ||
try { | ||
const result = await addFriendsFormService(req.params, req.body); | ||
if (result.status == "OK") { | ||
/// send report that object is created | ||
res.status(201).send(result.data); | ||
} else { | ||
res.status(409).send(result.data); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
res.status(500).send({ message: error }); | ||
} | ||
}; | ||
|
||
const getAllFriendsForms = async (req, res) => { | ||
try { | ||
const result = await getAllFriendsFormsService(req.params, req.body); | ||
if (result.status == "OK") { | ||
/// send report that object is created | ||
res.status(201).send(result.data); | ||
} else { | ||
res.status(409).send(result.data); | ||
} | ||
} catch (error) { | ||
console.log(error); | ||
res.status(500).send({ message: error }); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
addFriendsForm, | ||
getAllFriendsForms, | ||
}; | ||
|
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,11 @@ | ||
const express = require("express"); | ||
const { | ||
addFriendsForm, | ||
getAllFriendsForms, | ||
} = require("../controllers/friends.controller"); | ||
const friendsRouter = express.Router(); | ||
|
||
friendsRouter.get("/", getAllFriendsForms); | ||
friendsRouter.post("/", addFriendsForm); | ||
|
||
module.exports = friendsRouter; |
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const mdb = require("../services/mdb.services"); | ||
|
||
/** | ||
* Create a new friends form | ||
* @async | ||
* @param {Object} body - The body of the request that contains org information | ||
* @param {String} body.name - Name of user | ||
* @param {String} body.email - Email of user | ||
* @param {String} body.socialness - Level of introvert/extrovert-ness of user | ||
* @param {String} body.socialDesire - Preference of pairing with introvert or extrovert | ||
* @param {Array} body.hobbies - Hobbies of user | ||
* @param {Array} body.music - Preference of music | ||
* @param {Array} body.year - Academic standing of user | ||
* @param {Array} body.communication - Preference of communication | ||
* @param {String} body.userId - A UUID that identifies the user that created the org | ||
* @return {Object} - An object of {status: status, data: data}, where status can be "OK" or "ERROR" and data is the created org item if OK | ||
*/ | ||
exports.addFriendsFormService = async (params, body) => { | ||
try { | ||
// Check if user has already submitted a form | ||
// const user = await mdb.friends.findOne({ email: body.vanderbiltEmail }); | ||
// if (user) { | ||
// console.log("addFriendsFormService Error: User already submitted a friends form"); | ||
// return { status: "ERROR", data: "User already submitted a friends form" }; | ||
// } | ||
|
||
// Insert friends form into MongoDB | ||
const result = await mdb.friends.insertOne({ | ||
...body, | ||
}); | ||
|
||
console.log("addFriendsFormService Success:", result); | ||
return { status: "OK", data: body }; | ||
} catch (error) { | ||
console.log("addFriendsFormService Error:", error); | ||
return { status: "ERROR", data: error.message }; | ||
} | ||
}; | ||
|
||
exports.getAllFriendsFormsService = async (params, body) => { | ||
try { | ||
const forms = await mdb.friends.find({}).toArray(); | ||
console.log("getAllFriendsForms Success:", forms); | ||
return { status: "OK", data: forms }; | ||
} catch (error) { | ||
console.log("getAllFriendsForms Error:", error); | ||
return { status: "ERROR", data: error }; | ||
} | ||
}; | ||
|
||
/********************************* | ||
************ TESTING ************ | ||
*********************************/ | ||
setTimeout(function() { // fifth set of tests to run (user, org, roommate, acts, friends) | ||
console.log("I am friends testing, I am running"); | ||
let friendsForm = { | ||
'name': "Afriend", | ||
'email': "[email protected]", | ||
'socialness': "100", | ||
'socialDesire': "83", | ||
'hobbies': ["Gaming", "Watching Movies"], | ||
'music': ["Pop", "Classical", "Country"], | ||
'year': ["Senior"], | ||
'communication': ["Text", "Instagram"] | ||
} | ||
//let friend = exports.addFriendsFormService({}, friendsForm); console.log("Add friends form: ", friend); | ||
//console.log("ALL friends: ", exports.getAllFriendsFormsService()); | ||
}, 12500); |
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