Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleaned up code + bug fixing #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
29 changes: 20 additions & 9 deletions client/src/screens/StudyBuddy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ const StudyBuddyScreen = ({ route, navigation }: {route:any, navigation: any}) =
const [currentBuidling,setCurrentBuilding] = useState("");
const [currentRoom,setCurrentRoom] = useState("");
useEffect(() => {
console.log(route.params.params.userId);
// console.log(route.params.params.userId);
axios({
url: "http://localhost:3000/api/user/findUser",
method: "GET",
params: {
id: route.params.params.userId
}
}).then((response:any) => {
console.log(response.data.name);
// console.log(response.data.name);
setUserName(response.data.name);
if (response.data.hasRoom) {
setCurrentRoom(response.data.roomNumber);
Expand Down Expand Up @@ -126,18 +126,17 @@ const StudyBuddyScreen = ({ route, navigation }: {route:any, navigation: any}) =
room: currentRoom
}
}).then((response:any) => {
console.log("Successfully deleted building from building database")
// console.log("Successfully deleted building from building database")
axios({
url: "http://localhost:3000/api/user/removeUserRoom",
method: "POST",
data: {
id: route.params.params.userId
}
}).then((response:any) => {
console.log(response);
navigation.navigate("classroomFinderScreen",{
screen: 'Home'
})
// console.log(response);
// console.log("we should be here");
setHasBooking(false);
}).catch((error:any) => {
if (error.response) {
// Request made and server responded
Expand Down Expand Up @@ -173,7 +172,7 @@ const StudyBuddyScreen = ({ route, navigation }: {route:any, navigation: any}) =
return (
<SafeAreaView style={styles.container}>
{/* <Text>Open up App.tsx to start working on your app!</Text> */}
<Text>Buildings</Text>
<Text style={styles.titleText}>Buildings</Text>
<FlatList
style={styles.list}
data={dataSource}
Expand All @@ -190,7 +189,7 @@ const StudyBuddyScreen = ({ route, navigation }: {route:any, navigation: any}) =
}
else {
return (
<SafeAreaView style={styles.container}>
<SafeAreaView style={styles.containerTrue}>
{/* <Text>Open up App.tsx to start working on your app!</Text> */}
<Text>You're hosting a study room at {currentBuidling} {currentRoom}! Click below to end your session :(</Text>
<TouchableOpacity style={styles.loginBtn} onPress={() => removeSession()}>
Expand All @@ -209,6 +208,13 @@ const styles = StyleSheet.create({
// alignItems: 'center',
justifyContent: 'center',
},
containerTrue: {
flex: 1,
paddingHorizontal: 10,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
list: {
//flexDirection: "row"
},
Expand All @@ -228,6 +234,11 @@ const styles = StyleSheet.create({
buttonText: {
color: "#ffffff",
},
titleText: {
alignItems: "center",
textAlign: "center",
fontSize: 24
},

itemStyle: {
padding: 25,
Expand Down
45 changes: 26 additions & 19 deletions client/src/screens/StudyBuddyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const StudyBuddyList = ({route, navigation}) => {
const [userName,setUserName] = useState("");

useEffect(() => {
console.log(userId);
console.log("st")
// console.log(userId);
// console.log("st")
axios({
url: "http://localhost:3000/api/study/allCurrentSessions",
method: "GET",
Expand Down Expand Up @@ -67,7 +67,7 @@ const StudyBuddyList = ({route, navigation}) => {
id: userId
}
}).then((response:any) => {
console.log(response.data.name);
// console.log(response.data.name);
setUserName(response.data.name);
}).catch((error:any) => {
console.log("Some internal error getting the name");
Expand All @@ -86,7 +86,7 @@ const StudyBuddyList = ({route, navigation}) => {
room: room
}
}).then((response:any) => {
console.log("Successful building registration")
// console.log("Successful building registration")
axios({
url: "http://localhost:3000/api/user/addUserRoom",
method: "POST",
Expand All @@ -96,9 +96,11 @@ const StudyBuddyList = ({route, navigation}) => {
roomNum: room,
}
}).then((response:any) => {
console.log(response);
// console.log(response);
// console.log("added the new study session in frontend");
navigation.navigate("classroomFinderScreen",{
screen: 'Home'
screen: "ClassroomFinder",
params: { userId: userId }
})
}).catch((error:any) => {
if (error.response) {
Expand Down Expand Up @@ -127,17 +129,17 @@ const StudyBuddyList = ({route, navigation}) => {
// Something happened in setting up the request that triggered an Error
console.log('Error', error.message);
}
// Alert.alert(
// "Booking Failed",
// "That room is already taken!",
// [
// {
// text: "Retry",
// onPress: () => {
// }
// }
// ]
// )
Alert.alert(
"Booking Failed",
"That room is already taken!",
[
{
text: "Retry",
onPress: () => {
}
}
]
)
})
})

Expand Down Expand Up @@ -185,8 +187,8 @@ const StudyBuddyList = ({route, navigation}) => {
return (
<SafeAreaView style={styles.container}>
{/* <Text>Open up App.tsx to start working on your app!</Text> */}
<Text>{bName}</Text>
<TouchableOpacity onPress={() => {setDialog(true)}}>
<Text style={styles.titleText}>{bName}</Text>
<TouchableOpacity style={styles.titleText} onPress={() => {setDialog(true)}}>
<AntDesign name="pluscircle" size={24} color="#037a87" />
</TouchableOpacity>
<Dialog.Container visible={dialog}>
Expand Down Expand Up @@ -244,6 +246,11 @@ const styles = StyleSheet.create({
marginTop: 20,
backgroundColor: "#033f63",
},
titleText: {
alignItems: "center",
textAlign: "center",
fontSize: 24
},


itemStyle: {
Expand Down
4 changes: 2 additions & 2 deletions client/src/screens/classroomFinder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const ClassroomFinderScreen = () => {

const getToday = () => {
let today = new Date();
let dates = ["M", "T", "W", "Th", "F", "S", "Su"];
return dates[today.getDay() - 1];
let dates = ["M", "T", "W", "Th", "F"];
return dates[today.getDay() % 5];
}

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion client/src/screens/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export default function LoginScreen({ navigation }: {navigation: any}) {
}
}).then((response:any) => {
// console.log(response);
console.log("successful auth");
// console.log("successful auth");
//console.log(response.data);
navigation.navigate('classroomFinderScreen',{
//screen: "Study Buddy!",
Expand Down
2 changes: 1 addition & 1 deletion client/src/screens/signup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default function SignupScreen({ navigation }: {navigation: any}) {
}).then((response:any) => {
// console.log(response);
signupPassAlert();
console.log("successful signup");
// console.log("successful signup");
}).catch((error:any) => {
singupFailAlert(error);
if (error.response) {
Expand Down
10 changes: 5 additions & 5 deletions server/controllers/auth/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,30 @@ export const authLogin = async (req: Request, res: Response): Promise<any> => {

export const findUser = async (req: Request, res: Response): Promise<any> => {
User.findById(req.query.id,(error:any,data:any) => {
console.log(req.query.id);
// console.log(req.query.id);
if (error) {
console.log(error);
res.status(400).send("Can't find user");
}
else {
console.log(data);
console.log("here is your data");
// console.log(data);
// console.log("here is your data");
res.send(data);
}
})
}

export const userHasRoom = async (req: Request, res: Response): Promise<any> => {
try {
console.log(req.query.id);
// console.log(req.query.id);
axios({
url: "http://localhost:3000/api/user/findUser",
method: "GET",
params: {
id: req.query.id
}
}).then((response:any) => {
console.log(response.data.hasRoom);
// console.log(response.data.hasRoom);
if (response.data.hasRoom) res.send("yes");
else res.send("no");
}).catch((error:any) => {
Expand Down
48 changes: 27 additions & 21 deletions server/controllers/study/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,37 @@ import 'dotenv/config'
import User from "../../models/User";

export const addStudySession = async (req: Request, res: Response): Promise<any> => {
console.log("trying trying trinyg");
// const roomBooked = await Study.findOne({building : req.body.building, roomNumber: req.body.room});
// if (roomBooked) {
// return res.status(400).send("Room already booked");
// }
const studySession = new Study({
name: req.body.name,
building: req.body.building,
room: req.body.room
});

//TODO: handle updating user
try {
const savedSession = await studySession.save();
res.send({room:req.body.room});
console.log("Successfully added study session");
// console.log("trying trying trinyg");
const roomBooked = await Study.findOne({building : req.body.building, room: req.body.room});
if (roomBooked) {
// console.log(req.body.room);
// console.log(roomBooked);
res.status(400).send("Room already booked");
}
catch (err) {
res.status(400).send(err);
console.log("err");
else {
const studySession = new Study({
name: req.body.name,
building: req.body.building,
room: req.body.room
});


try {
const savedSession = await studySession.save();
res.send({room:req.body.room});
// console.log("Successfully added study session");
}
catch (err) {
res.status(400).send(err);
console.log("err");
}
}
}

export const removeStudySession = async (req: Request, res: Response): Promise<any> => {
Study.deleteOne({building : req.body.building, roomNumber: req.body.room}).then(function() {
// console.log(req.body.building);
// console.log(req.body.room);
Study.deleteOne({building : req.body.building, room: req.body.room}).then(function() {
res.send("successfully deleted")
}).catch(function() {
res.status(400).send("couldnt remove from table");
Expand All @@ -40,7 +46,7 @@ export const removeStudySession = async (req: Request, res: Response): Promise<a

export const allCurrentSessions = async (req: Request, res: Response): Promise<any> => {
// const activeSessions = Study.find({building: req.body.building})
console.log(req.query.building);
// console.log(req.query.building);
Study.find({building: req.query.building}).then(students => {
//console.log(students);
res.send(students);
Expand Down