Skip to content

Commit

Permalink
Added backend friend form functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheGElCOgecko committed Apr 11, 2024
1 parent f03ad35 commit 5a4d1da
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 69 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"Mayfield",
"PEMDAS",
"roomies",
"socialness",
"Tolman",
"Tyeire",
"vunet",
Expand Down
40 changes: 40 additions & 0 deletions backend/controllers/friends.controller.js
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,
};

11 changes: 11 additions & 0 deletions backend/routers/friends.router.js
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;
4 changes: 3 additions & 1 deletion backend/routers/root.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ const express = require('express');
const userRouter = require('./user.router');
const orgRouter = require('./org.router');
const actRouter = require('./activities.router');
const roommateRouter = require("./roommate.router");
const roommateRouter = require("./friends.router");
const friendsRouter = require("./friends.router");

const RootRouter = express.Router();

Expand All @@ -15,5 +16,6 @@ RootRouter.use('/user', userRouter);
RootRouter.use('/org', orgRouter);
RootRouter.use('/act', actRouter);
RootRouter.use("/roommate", roommateRouter);
RootRouter.use("/friends", friendsRouter);

module.exports = RootRouter;
23 changes: 6 additions & 17 deletions backend/services/activities.services.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ const { randomUUID } = require('crypto');
* Create a new act
* @async
* @param {Object} body - The body of the request that contains act information
* @param {String} body.name - The title of the act
* @param {String} body.description - The description of the act
* @param {Array} body.tags - An array of tags that are associated with this act
* @param {Array} body.membershipIds - An array of membershipIds to show users that are in this act
* @param {String} body.name - The name of the act
* @param {String} body.email - The email contact for the act
* @param {String} body.date - The date of the act
* @param {String} body.organizer - The organizer of the act
* @param {String} body.userId - A UUID that identifies the user that created the act
* @return {Object} - An object of {status: status, data: data}, where status can be "OK" or "ERROR" and data is the created act item if OK
*/
Expand Down Expand Up @@ -74,18 +74,11 @@ exports.getAllActsService = async (params, body) => {
}
}



/**
* Update an act by actId
* @async
* @param {Object} body - The body of the request that contains act information
* @param {Object} params - The parameters of the request that contains act information
* @param {String} params.actId - An UUID that uniquely identifies a act
* @param {String} body.name - The title of the act
* @param {String} body.description - The description of the act
* @param {Array} body.tags - An array of tags that are associated with this act
* @param {Array} body.membershipIds - An array of membershipIds to show users that are in this act
* @return {Object} - An object of {status: status, data: data}, where status can be "OK" or "ERROR" and data is the updated act item if OK
*/
exports.updateActService = async (params, body) => {
Expand Down Expand Up @@ -120,8 +113,6 @@ exports.updateActService = async (params, body) => {
}
}



/**
* Delete a act by actId
* @async
Expand Down Expand Up @@ -153,7 +144,6 @@ exports.deleteActService = async (params) => {
* @param {Object} body - The body of the request that contains act information
* @param {Object} params - The parameters of the request that contains act information
* @param {String} params.actId - An UUID that uniquely identifies a act
* @param {String} body.membershipId - An UUID that uniquely identifies the membership item
* @return {Object} - An object of {status: status, data: data}, where status can be "OK" or "ERROR" and data is the updated act item if OK
*/
exports.addMemberActService = async (params, body) => {
Expand All @@ -180,8 +170,7 @@ exports.addMemberActService = async (params, body) => {
* @async
* @param {Object} body - The body of the request that contains act information
* @param {Object} params - The parameters of the request that contains act information
* @param {String} params.actId - An UUID that uniquely identifies a act
* @param {String} body.membershipId - An UUID that uniquely identifies the membership item that is to be removed
* @param {String} params.actId - An UUID that uniquely identifies an act
* @return {Object} - An object of {status: status, data: data}, where status can be "OK" or "ERROR" and data is the updated act item if OK
*/
exports.removeMemberActService = async (params, body) => {
Expand All @@ -206,7 +195,7 @@ exports.removeMemberActService = async (params, body) => {
/*********************************
************ TESTING ************
*********************************/
setTimeout(function() { // second set of tests to run (user, act, roommate)
setTimeout(function() { // fourth set of tests to run (user, org, roommate, acts, friends)
console.log("I am activity testing, I am running");
let body1 = {
'name': "Rites of Spring",
Expand Down
68 changes: 68 additions & 0 deletions backend/services/friends.services.js
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);
11 changes: 1 addition & 10 deletions backend/services/org.services.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,11 @@ exports.getAllOrgsService = async (params, body) => {
}
}



/**
* Update an org by orgId
* @async
* @param {Object} body - The body of the request that contains org information
* @param {Object} params - The parameters of the request that contains org information
* @param {String} params.orgId - An UUID that uniquely identifies a org
* @param {String} body.name - The title of the org
* @param {String} body.description - The description of the org
* @param {Array} body.tags - An array of tags that are associated with this org
* @param {Array} body.membershipIds - An array of membershipIds to show users that are in this org
* @return {Object} - An object of {status: status, data: data}, where status can be "OK" or "ERROR" and data is the updated org item if OK
*/
exports.updateOrgService = async (params, body) => {
Expand Down Expand Up @@ -120,8 +113,6 @@ exports.updateOrgService = async (params, body) => {
}
}



/**
* Delete a org by orgId
* @async
Expand Down Expand Up @@ -206,7 +197,7 @@ exports.removeMemberOrgService = async (params, body) => {
/*********************************
************ TESTING ************
*********************************/
setTimeout(function() { // second set of tests to run (user, org, roommate)
setTimeout(function() { // second set of tests to run (user, org, roommate, acts, friends)
console.log("I am org testing, I am running");
let body1 = {
'name': "Geico",
Expand Down
62 changes: 25 additions & 37 deletions backend/services/roommate.services.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
const mdb = require("../services/mdb.services");

/**
* Create a new roommate form
* @async
* @param {Object} body - The body of the request that contains org information
* @param {String} body.fullName - The name of user
* @param {String} body.vanderbiltEmail - Email of user
* @param {String} body.vunetId - VUNet ID
* @param {String} body.pets - Whether user owns pets
* @param {String} body.sleepSchedulePreferences - Preferences of sleep schedule
* @param {String} body.cleanliness - Level of cleanliness
* @param {String} body.overnightGuestsFrequency - Frequency of overnight guests
* @param {String} body.studyNoisePreference - Preference of study noise
* @param {String} body.studyLocationPreference - Preference of study location
* @param {String} body.friendsOverFrequency - Frequency user has friends over
* @param {String} body.smoke - Whether user smokes
* @param {String} body.comfortableWithSmokers - Comfort level with smokers
* @param {String} body.alcoholComfortLevel - Comfort level of alcohol
* @param {String} body.conflictResolution - Preferred method of conflict resolution
* @param {String} body.locationPreference - Residential location of preference
* @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.addRoommateFormService = async (params, body) => {
try {
// Check if user has already submitted a form
Expand Down Expand Up @@ -36,41 +58,7 @@ exports.getAllRoommateFormsService = async (params, body) => {
/*********************************
************ TESTING ************
*********************************/
/* RECOPIED FUNCTIONS */
addRoommateFormService = async (params, body) => {
try {
// Check if user has already submitted a form
// const user = await mdb.roomies.findOne({ email: body.vanderbiltEmail });
// if (user) {
// console.log("addRoommateFormService Error: User already submitted a roommate form");
// return { status: "ERROR", data: "User already submitted a roommate form" };
// }

// Insert roommate form into MongoDB
const result = await mdb.roomies.insertOne({
...body,
});

console.log("addRoommateFormService Success:", result);
return { status: "OK", data: body };
} catch (error) {
console.log("addRoommateFormService Error:", error);
return { status: "ERROR", data: error.message };
}
};
getAllRoommateFormsService = async (params, body) => {
try {
const forms = await mdb.roomies.find({}).toArray();
console.log("getAllRoommateForms Success:", forms);
return { status: "OK", data: forms };
} catch (error) {
console.log("getAllRoommateForms Error:", error);
return { status: "ERROR", data: error };
}
};

/* TESTING */
setTimeout(function() { // third set of tests to run (user, org, roommate)
setTimeout(function() { // third set of tests to run (user, org, roommate, acts, friends)
console.log("I am roommate testing, I am running");
let roomForm = {
'fullName': "Nnaammee",
Expand All @@ -89,6 +77,6 @@ setTimeout(function() { // third set of tests to run (user, org, roommate)
'conflictResolution': "Need time to cool off",
'locationPreference': "McTyeire"
}
//let room = addRoommateFormService({}, roomForm); console.log("Add roommate form: ", room);
//console.log("ALL roommates: ", getAllRoommateFormsService());
//let room = exports.addRoommateFormService({}, roomForm); console.log("Add roommate form: ", room);
//console.log("ALL roommates: ", exports.getAllRoommateFormsService());
}, 7500);
5 changes: 1 addition & 4 deletions backend/services/user.services.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ exports.getAllUsersService = async (params, body) => {
* @param {Object} body - The body of the request that contains user information
* @param {Object} params - The parameters of the request that contains user information
* @param {String} params.userId - An UUID that uniquely identifies a user
* @param {String} body.name - The name of the user
* @param {String} body.email - The email of the user
* @param {String} body.phoneNumber - The phone number of the user
* @return {Object} - An object of {status: status, data: data}, where status can be "OK" or "ERROR" and data is the updated user item if OK
*/
exports.updateUserByIdService = async(params, body) => {
Expand Down Expand Up @@ -140,7 +137,7 @@ exports.deleteUserByIdService = async(params, body) => {
/*********************************
************ TESTING ************
*********************************/
setTimeout(function() { // first set of tests to run (user, org, roommate)
setTimeout(function() { // first set of tests to run (user, org, roommate, acts, friends)
console.log("I am user testing, I am running");
let body1 = {
'name': "Martin",
Expand Down

0 comments on commit 5a4d1da

Please sign in to comment.