@@ -21,7 +21,6 @@ const passwordMatch = (async(passwordFromUser, savedPasswordFromDB) => {
2121// const active = user.isOnline;
2222// return await User.findOneAndUpdate({ username: user.username }, { isOnline: !active })
2323// })
24-
2524export const getUser = async ( req , res ) => {
2625 try {
2726 const userId = req . session . userID ;
@@ -71,8 +70,7 @@ export const createUser = async(req, res) => {
7170 username,
7271 email,
7372 password : hashedPassword ,
74- isOneline : true ,
75- pfp : "" , //pfp string url, save a temp one for now after creation
73+ isOneline : true , //got rid of pfp so it uses the default values
7674 description : "" , //description, empty for now (could default to "" in the schema)
7775 friendsList : [ ] ,
7876 friendRequest : [ ] ,
@@ -485,7 +483,7 @@ export const acceptFriendRequest = async(req, res) => {
485483export const rejectFriendRequest = async ( req , res ) => {
486484 try {
487485 const userId = req . params . id
488- const user = await User . findByid ( userId )
486+ const user = await User . findById ( userId )
489487
490488 const otherUser = req . body . friendId ;
491489 const rejectingUser = await User . findById ( otherUser ) ;
@@ -499,6 +497,10 @@ export const rejectFriendRequest = async(req, res) => {
499497 return ;
500498 }
501499
500+ if ( ! user . friendRequests . includes ( otherUser ) ) {
501+ return res . status ( 400 ) . json ( { message : "No such friend request exists" } ) ;
502+ }
503+
502504 user . friendRequests . pull ( rejectingUser . _id ) ;
503505 await user . save ( )
504506 res . status ( 200 ) . json ( { message : 'Friend request rejected!' } )
@@ -577,4 +579,22 @@ export const updateUsersCoins = async (req, res) => {
577579 catch ( e ) {
578580 res . status ( 500 ) . json ( { error : "error fetching user's coins" } )
579581 }
582+ }
583+ export const updateUserMonstersSlain = async ( req , res ) => {
584+ try {
585+ const userId = req . params . id ;
586+ const monstersSlain = req . body . monstersSlain ;
587+ const user = await User . findById ( userId ) . select ( "monstersSlain" ) ;
588+ if ( ! user ) {
589+ res . status ( 404 ) . json ( { error : "user doesn't exist" } )
590+ return
591+ }
592+ const adjust = user . monstersSlain + monstersSlain ;
593+ const updatedUsers = await User . findByIdAndUpdate ( userId , { monstersSlain : adjust } , { new : true } ) . select ( "monstersSlain" )
594+ await updatedUsers . save ( ) ;
595+ res . status ( 200 ) . json ( { monstersSlain : updatedUsers . monstersSlain } )
596+ }
597+ catch ( e ) {
598+ res . status ( 500 ) . json ( { error : "error updating user's monsters slain" } ) ;
599+ }
580600}
0 commit comments