Skip to content

Commit

Permalink
implement search game logic in app b00tc4mp#84
Browse files Browse the repository at this point in the history
  • Loading branch information
Eden23 committed Aug 13, 2024
1 parent 0dbd65d commit 808942e
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
4 changes: 3 additions & 1 deletion staff/marti-herms/project/V-HUB/app/logic/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import registerUser from './registerUser.js'
import isUserLoggedIn from './isUserLoggedIn.js'
import getUserUsername from './getUserUsername.js'
import registerGame from './registerGame.js'
import searchGame from './searchGame.js'

const logic = {
loginUser,
logoutUser,
registerUser,
isUserLoggedIn,
getUserUsername,
registerGame
registerGame,
searchGame
}

export default logic
29 changes: 29 additions & 0 deletions staff/marti-herms/project/V-HUB/app/logic/searchGame.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { validate, errors } from 'com'

const { SystemError } = errors

export default (query) => {
validate.string(query, 'query')

return fetch(`${import.meta.env.VITE_API_URL}/games/search?q=${query}`, {
headers: { Authorization: `Bearer ${sessionStorage.token}` }
})
.catch(error => { throw new SystemError(error.message) })
.then(response => {
const { status } = response

if (status === 200) {
return response.json()
.then(games => games)
}

return response.json()
.then(body => {
const { error, message } = body

const constructor = errors[error]

throw new constructor(message)
})
})
}

0 comments on commit 808942e

Please sign in to comment.