You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

30 lines
1.0 KiB

import { Request, Response, Router } from 'express';
import { getUserList } from './models/user.model';
import { createToken } from '../lib/jwt';
import { getUserSecure } from './user.service';
import { requireAdminOrMod, requireUserToken } from '../middleware/user.middleware';
const router = Router();
router.get('/', async (req: Request, res: Response) => { return res.json({ users: await getUserList() }); });
// This just makes a token for testing for now
router.get('/login', async (req: Request, res: Response) => {
const jwt = await createToken({ user_id: 1, token_id: 'uuidv4', hostname: 'localhost' });
return res.json({ jwt });
});
router.get('/auth-test', requireUserToken, async (req: Request, res: Response) => {
return res.json({
users: await getUserList(),
});
});
router.get('/:userId', requireAdminOrMod, async (req: Request, res: Response) => {
return res.json({
user: await getUserSecure(parseInt(req.params.userId)),
});
});
// eslint-disable-next-line import/prefer-default-export
export const UserRoutes = router;