Skip to content

Commit

Permalink
add routes without test b00tc4mp#257
Browse files Browse the repository at this point in the history
  • Loading branch information
Yeyusin committed Jul 5, 2024
1 parent c1b41f2 commit adbfdb0
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 5 deletions.
106 changes: 105 additions & 1 deletion staff/sergio-ocaña/project/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,112 @@ mongoose.connect(MONGO_URL)

error = new MatchError(error.message)

res.status(status).json({ error: error.constructor.name, message: error.message })
}
res.status(status).json({ error: error.constructor.name, message: error.message })
}
})

server.delete('cinema/delete/:cinemaId', (req, res) => {
try {
const { authorization } = req.headers

const token = authorization.slice(7)

const { sub: userId } = jwt.verify(token, JWT_SECRET)

const cinemaId = req.params

logic.deleteCinema(userId, cinemaId)
.then(() => res.status(204).send())
.catch(error => {
let status = 500

if (error instanceof MatchError)
status = 401
res.status(status).json({ error: error.constructor.name, message: error.message })
})

} catch (error) {
let status = 500

if (error instanceof TypeError || error instanceof RangeError || error instanceof ContentError)
status = 400

else if (error instanceof JsonWebTokenError || error instanceof TokenExpiredError) {
status = 401

error = new MatchError(error.message)

}
res.status(status).json({ error: error.constructor.name, message: error.message })
}
})

server.patch('users/:cinemaId', (req, res) => {
try {
const { authorization } = req.headers

const token = authorization.slice(7)

const { sub: userId } = jwt.verify(token)

const { cinemaId } = req.params

logic.addCinemaToManager(userId, cinemaId)
.then(() => { res.status(200).send() })
.catch(error => {
let status = 500

if (error instanceof MatchError)
status = 401

res.status(status).json({ error: error.constructor.name, message: error.message })
})
} catch (error) {
let status = 500

if (error instanceof TypeError || error instanceof RangeError || error instanceof ContentError)
status = 400
else if (error instanceof JsonWebTokenError || error instanceof TokenExpiredError) {
status = 401

error = new MatchError(error.message)
}
res.status(status).json({ error: error.constructor.name, message: error.message })
}
})

server.delete('users/:cinemaId/delete', (req, res) => {
try {
const { authorization } = req.headers

const token = authorization.slice(7)

const { sub: userId } = jwt.verify(token, JWT_SECRET)

const { cinemaId } = req.params

logic.deleteCinemaToManager(userId, cinemaId)
.then(() => res.status(204).send())
.catch(error => {
let status = 500

if (error instanceof MatchError)
status = 401

res.status(status).json({ error: error.constructor.name, message: error.message })
})
} catch (error) {
let status = 500

if (error instanceof TypeError || error instanceof RangeError || error instanceof ContentError)
status = 400
else if (error instanceof JsonWebTokenError || error instanceof TokenExpiredError) {
status = 401

error = new MatchError(error.message)
}
res.status(status).json({ error: error.constructor.name, message: error.message })
}
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ function deleteCinemaToManager(userId, cinemaId) {
return User.findByIdAndUpdate(userId, { $unset: { cinema } })

})


})


}
export default deleteCinemaToManager

0 comments on commit adbfdb0

Please sign in to comment.