Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions server/src/routes/api/v1/sessions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@ router.get('/hasValid/:id', async (req, res) => {
req.headers['react-map-secret'] === api.reactMapSecret
) {
const results = await Session.query().whereRaw(
`json_extract(data, '$.passport.user.id') = ${req.params.id}`,
`json_extract(data, '$.passport.user.id') = ${req.params.id}
OR json_extract(data, '$.passport.user.discordId') = "${req.params.id}"
OR json_extract(data, '$.passport.user.telegramId') = "${req.params.id}"`,
)
res.status(200).json({
valid: Boolean(results.length),
valid: !!results.length,
length: results.length,
})
console.log(`[API] api/v1/sessions/hasValid/${req.params.id}`)
Expand All @@ -50,7 +52,11 @@ router.get('/clearSessions/:id', async (req, res) => {
req.headers['react-map-secret'] === api.reactMapSecret
) {
const results = await Session.query()
.whereRaw(`json_extract(data, '$.passport.user.id') = ${req.params.id}`)
.whereRaw(
`json_extract(data, '$.passport.user.id') = ${req.params.id}
OR json_extract(data, '$.passport.user.discordId') = "${req.params.id}"
OR json_extract(data, '$.passport.user.telegramId') = "${req.params.id}"`,
)
.delete()
res.status(200).json({ results })
console.log(`[API] api/v1/sessions/clearSessions/${req.params.id}`)
Expand Down
49 changes: 46 additions & 3 deletions server/src/routes/api/v1/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ router.get('/', async (req, res) => {
console.log('[API] api/v1/users')
} catch (e) {
console.error('[API Error] api/v1/sessions', e)
res.status(500).json({ status: 'ServerError', reason: e.message })
res.status(500).json({ status: 'error', reason: e.message })
}
})

Expand All @@ -26,14 +26,57 @@ router.get('/:id', async (req, res) => {
api.reactMapSecret &&
req.headers['react-map-secret'] === api.reactMapSecret
) {
res.status(200).json(await User.query().findById(req.params.id))
const user = await User.query().findById(req.params.id)
res
.status(200)
.json(user || { status: 'error', reason: 'User Not Found' })
} else {
throw new Error('Incorrect or missing API secret')
}
console.log(`[API] api/v1/users/${req.params.id}`)
} catch (e) {
console.error(`[API Error] api/v1/users/${req.params.id}`, e)
res.status(500).json({ status: 'ServerError', reason: e.message })
res.status(500).json({ status: 'error', reason: e.message })
}
})

router.get('/discord/:id', async (req, res) => {
try {
if (
api.reactMapSecret &&
req.headers['react-map-secret'] === api.reactMapSecret
) {
const user = await User.query().where('discordId', req.params.id).first()
res
.status(200)
.json(user || { status: 'error', reason: 'User Not Found' })
} else {
throw new Error('Incorrect or missing API secret')
}
console.log(`[API] api/v1/users/discord/${req.params.id}`)
} catch (e) {
console.error(`[API Error] api/v1/users/discord/${req.params.id}`, e)
res.status(500).json({ status: 'error', reason: e.message })
}
})

router.get('/telegram/:id', async (req, res) => {
try {
if (
api.reactMapSecret &&
req.headers['react-map-secret'] === api.reactMapSecret
) {
const user = await User.query().where('telegramId', req.params.id).first()
res
.status(200)
.json(user || { status: 'error', reason: 'User Not Found' })
} else {
throw new Error('Incorrect or missing API secret')
}
console.log(`[API] api/v1/users/telegram/${req.params.id}`)
} catch (e) {
console.error(`[API Error] api/v1/users/telegram/${req.params.id}`, e)
res.status(500).json({ status: 'error', reason: e.message })
}
})

Expand Down