mirror of
https://github.com/ragestudio/comty.git
synced 2025-06-10 02:54:15 +00:00
use res.json
to parse responses
This commit is contained in:
parent
402f0d4557
commit
2a9f086f14
@ -8,7 +8,7 @@ function resolveToUrl(filepath) {
|
||||
}
|
||||
|
||||
export default class FilesController extends ComplexController {
|
||||
static refName = "FilesController"
|
||||
static disabled = true
|
||||
|
||||
get = {
|
||||
"/uploads/:id": {
|
||||
|
@ -61,11 +61,11 @@ export default class RolesController extends ComplexController {
|
||||
}, async (req, res) => {
|
||||
// check if issuer user is admin
|
||||
if (!req.isAdmin()) {
|
||||
return res.status(403).send("You do not have administrator permission")
|
||||
return res.status(403).json("You do not have administrator permission")
|
||||
}
|
||||
|
||||
if (!Array.isArray(req.selection.update)) {
|
||||
return res.status(400).send("Invalid update request")
|
||||
return res.status(400).json("Invalid update request")
|
||||
}
|
||||
|
||||
req.selection.update.forEach(async (update) => {
|
||||
@ -82,7 +82,7 @@ export default class RolesController extends ComplexController {
|
||||
}
|
||||
})
|
||||
|
||||
return res.send("done")
|
||||
return res.json("done")
|
||||
}),
|
||||
},
|
||||
}
|
||||
|
@ -75,18 +75,18 @@ export default class SessionController extends ComplexController {
|
||||
const { token, user_id } = req.body
|
||||
|
||||
if (typeof user_id === "undefined") {
|
||||
return res.status(400).send("No user_id provided")
|
||||
return res.status(400).json("No user_id provided")
|
||||
}
|
||||
if (typeof token === "undefined") {
|
||||
return res.status(400).send("No token provided")
|
||||
return res.status(400).json("No token provided")
|
||||
}
|
||||
|
||||
const session = await Session.findOneAndDelete({ user_id, token })
|
||||
if (session) {
|
||||
return res.send("done")
|
||||
return res.json("done")
|
||||
}
|
||||
|
||||
return res.status(404).send("not found")
|
||||
return res.status(404).json("not found")
|
||||
},
|
||||
},
|
||||
"/sessions": {
|
||||
@ -95,15 +95,15 @@ export default class SessionController extends ComplexController {
|
||||
const { user_id } = req.body
|
||||
|
||||
if (typeof user_id === "undefined") {
|
||||
return res.status(400).send("No user_id provided")
|
||||
return res.status(400).json("No user_id provided")
|
||||
}
|
||||
|
||||
const allSessions = await Session.deleteMany({ user_id })
|
||||
if (allSessions) {
|
||||
return res.send("done")
|
||||
return res.json("done")
|
||||
}
|
||||
|
||||
return res.status(404).send("not found")
|
||||
return res.status(404).json("not found")
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -390,7 +390,7 @@ export default class UserController extends ComplexController {
|
||||
})
|
||||
})
|
||||
.catch((err) => {
|
||||
return res.send(500).json({
|
||||
return res.json(500).json({
|
||||
error: err.message
|
||||
})
|
||||
})
|
||||
@ -420,7 +420,7 @@ export default class UserController extends ComplexController {
|
||||
})
|
||||
})
|
||||
.catch((err) => {
|
||||
return res.send(500).json({
|
||||
return res.json(500).json({
|
||||
error: err.message
|
||||
})
|
||||
})
|
||||
|
@ -1,6 +1,6 @@
|
||||
export default (req, res, next) => {
|
||||
if (!req.user.roles.includes("admin")) {
|
||||
return res.status(403).send({ error: "To make this request it is necessary to have administrator permissions" })
|
||||
return res.status(403).json({ error: "To make this request it is necessary to have administrator permissions" })
|
||||
}
|
||||
|
||||
next()
|
||||
|
@ -4,7 +4,7 @@ import jwt from "jsonwebtoken"
|
||||
|
||||
export default (req, res, next) => {
|
||||
function reject(description) {
|
||||
return res.status(401).send({ error: `${description ?? "Invalid session"}` })
|
||||
return res.status(401).json({ error: `${description ?? "Invalid session"}` })
|
||||
}
|
||||
|
||||
const authHeader = req.headers?.authorization?.split(" ")
|
||||
@ -34,7 +34,7 @@ export default (req, res, next) => {
|
||||
const userData = await User.findOne({ _id: currentSession.user_id }).select("+refreshToken")
|
||||
|
||||
if (!userData) {
|
||||
return res.status(404).send({ error: "No user data found" })
|
||||
return res.status(404).json({ error: "No user data found" })
|
||||
}
|
||||
|
||||
if (err) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user