Skip to content

Commit

Permalink
implement get user chats logic in api; change jsonBodyParser middlewa…
Browse files Browse the repository at this point in the history
…re to express middleware b00tc4mp#84
  • Loading branch information
Eden23 committed Aug 27, 2024
1 parent 7ca0ce1 commit e2cea66
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { logic } from 'core'

export default (req, res, next) => {
const { userId } = req

const { targetUserId } = req.params

try {
logic.getUserChats(userId, targetUserId)
.then(chats => res.json(chats))
.catch(error => next(error))
} catch (error) {
next(error)
}
}
2 changes: 2 additions & 0 deletions staff/marti-herms/project/G-HUB/api/handlers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import editUserUsernameHandler from './editUserUsernameHandler.js'
import openChatHandler from './openChatHandler.js'
import sendMessageHandler from './sendMessageHandler.js'
import getChatMessagesHandler from './getChatMessagesHandler.js'
import getUserChatsHandler from './getUserChatsHandler.js'

const handle = {
authenticateUser: authenticateUserHandler,
Expand All @@ -35,6 +36,7 @@ const handle = {
getGamesReviews: getGamesReviewsHandler,
getUser: getUserHandler,
getUserAvatar: getUserAvatarHandler,
getUserChats: getUserChatsHandler,
getUserFavs: getUserFavsHandler,
getUserFollowers: getUserFollowersHandler,
getUserFollowing: getUserFollowingHandler,
Expand Down
20 changes: 12 additions & 8 deletions staff/marti-herms/project/G-HUB/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cors from 'cors'

import { mongoose } from 'core'

import { jsonBodyParser, jwtVerifier, errorHandler } from './middleware/index.js'
import { jwtVerifier, errorHandler } from './middleware/index.js'

import handle from './handlers/index.js'

Expand All @@ -16,13 +16,15 @@ mongoose.connect(process.env.MONGODB_URI)

api.use(cors())

api.post('/users', jsonBodyParser, handle.registerUser)
api.use(json())

api.post('/users/auth', jsonBodyParser, handle.authenticateUser)
api.post('/users', handle.registerUser)

api.patch('/users/username', jwtVerifier, jsonBodyParser, handle.editUserUsername)
api.post('/users/auth', handle.authenticateUser)

api.patch('/users/avatar', jwtVerifier, jsonBodyParser, handle.editUserAvatar)
api.patch('/users/username', jwtVerifier, handle.editUserUsername)

api.patch('/users/avatar', jwtVerifier, handle.editUserAvatar)

api.get('/users/search', jwtVerifier, handle.searchUser)

Expand All @@ -38,7 +40,7 @@ mongoose.connect(process.env.MONGODB_URI)

api.patch('/users/:targetUserId/follow', jwtVerifier, handle.toggleFollowUser)

api.post('/games', jwtVerifier, jsonBodyParser, handle.registerGame)
api.post('/games', jwtVerifier, handle.registerGame)

api.get('/games/search', jwtVerifier, handle.searchGame)

Expand All @@ -56,16 +58,18 @@ mongoose.connect(process.env.MONGODB_URI)

api.patch('/games/:gameId/favs', jwtVerifier, handle.toggleFavGame)

api.post('/games/:gameId/review', jwtVerifier, jsonBodyParser, handle.makeReview)
api.post('/games/:gameId/review', jwtVerifier, handle.makeReview)

api.delete('/reviews/:reviewId', jwtVerifier, handle.deleteReview)

api.get('/chat/:targetUserId', jwtVerifier, handle.openChat)

api.post('/chat/:chatId/messages', jwtVerifier, jsonBodyParser, handle.sendMessage)
api.post('/chat/:chatId/messages', jwtVerifier, handle.sendMessage)

api.get('/chat/:chatId/messages', jwtVerifier, handle.getChatMessages)

api.get('/chats/:targetUserId', jwtVerifier, handle.getUserChats)

api.use(errorHandler)

api.listen(process.env.PORT, () => console.info(`API listening on PORT ${process.env.PORT}`))
Expand Down
2 changes: 2 additions & 0 deletions staff/marti-herms/project/G-HUB/app/src/home/Game.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ export default function Game({ makeReviewVisibility, onCancel }) {
try {
logic.makeReview(gameId, comment, rate || 0)
.then(() => {
console.log('hello')

onCancel()

loadReviews()
Expand Down

0 comments on commit e2cea66

Please sign in to comment.