mirror of
https://github.com/psforever/PSFPortal.git
synced 2026-07-11 22:44:35 +00:00
Initial commit
This commit is contained in:
commit
20946fdb43
49 changed files with 2393 additions and 0 deletions
108
api/admin.js
Normal file
108
api/admin.js
Normal file
|
|
@ -0,0 +1,108 @@
|
|||
import express from 'express'
|
||||
import * as db from './db.js'
|
||||
import { get_pagination, fetch_user_middleware } from './util.js'
|
||||
|
||||
const api = express.Router();
|
||||
|
||||
api.param("user", fetch_user_middleware);
|
||||
|
||||
api.get('/users', async (req, res, next) => {
|
||||
const pagination = get_pagination(req);
|
||||
|
||||
try {
|
||||
const accounts = await db.get_accounts_login_info(pagination, db.ACCOUNT.CREATED, db.SQL_ORDER.DESCENDING);
|
||||
res.status(200).json({ users: accounts, page: pagination})
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
res.status(500).json({ message: 'error' });
|
||||
}
|
||||
});
|
||||
|
||||
api.post('/search', async (req, res, next) => {
|
||||
const pagination = get_pagination(req);
|
||||
|
||||
let search = req.body.search;
|
||||
|
||||
if (!search || search.length < 3) {
|
||||
res.status(400).json({ message: 'Need a longer search term' });
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
const items = await db.search(search, pagination);
|
||||
res.status(200).json({ items: items, page: pagination})
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
res.status(500).json({ message: 'error' });
|
||||
}
|
||||
});
|
||||
|
||||
api.get('/user/:user', async (req, res, next) => {
|
||||
const account = req.user;
|
||||
|
||||
res.status(200).json({ id : account.id, name: account.username });
|
||||
});
|
||||
|
||||
api.post('/user/:user/add_gm', async (req, res, next) => {
|
||||
const account = req.user;
|
||||
|
||||
try {
|
||||
await db.update_account(account.id, {"gm" : true})
|
||||
res.status(200).json({});
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
res.status(500).json({ message: 'error' });
|
||||
}
|
||||
});
|
||||
|
||||
api.post('/user/:user/remove_gm', async (req, res, next) => {
|
||||
const account = req.user;
|
||||
|
||||
try {
|
||||
await db.update_account(account.id, {"gm" : false})
|
||||
res.status(200).json({});
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
res.status(500).json({ message: 'error' });
|
||||
}
|
||||
});
|
||||
|
||||
api.post('/user/:user/ban', async (req, res, next) => {
|
||||
const account = req.user;
|
||||
|
||||
try {
|
||||
// also drop GM if they had it...
|
||||
await db.update_account(account.id, {"inactive" : true, "gm" : false})
|
||||
res.status(200).json({});
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
res.status(500).json({ message: 'error' });
|
||||
}
|
||||
});
|
||||
|
||||
api.post('/user/:user/unban', async (req, res, next) => {
|
||||
const account = req.user;
|
||||
|
||||
try {
|
||||
await db.update_account(account.id, {"inactive" : false})
|
||||
res.status(200).json({});
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
res.status(500).json({ message: 'error' });
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
api.get('/characters', async (req, res, next) => {
|
||||
const pagination = get_pagination(req);
|
||||
|
||||
try {
|
||||
const characters = await db.get_characters(pagination, db.CHARACTER.LAST_LOGIN, db.SQL_ORDER.DESCENDING);
|
||||
res.status(200).json({ characters: characters, page: pagination})
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
res.status(500).json({ message: 'error' });
|
||||
}
|
||||
});
|
||||
|
||||
export default api;
|
||||
Loading…
Add table
Add a link
Reference in a new issue