add get all users/groups routes

This commit is contained in:
Arthur Lu 2024-07-03 23:46:00 +00:00
parent 7f48f49445
commit 800033c6f8
4 changed files with 52 additions and 0 deletions

View File

@ -76,6 +76,13 @@ class USER_BACKEND extends BACKEND {
*/
getUser (user, params = null) {}
/**
* Get all users from backend
* @param {Object} params authentication params, usually req.cookies
* @returns {Array} containing each user data from this backend
*/
getAllUsers (params = null) {}
/**
* Modify user in backend
* @param {{id: string, realm: string}} user
@ -110,6 +117,13 @@ class USER_BACKEND extends BACKEND {
*/
getGroup (group, params = null) {}
/**
* Get all users from backend
* @param {Object} params authentication params, usually req.cookies
* @returns {Array} containing each group data from this backend
*/
getAllGroups (params = null) {}
/**
* Modify group in backend
* @param {{id: string}} group
@ -190,6 +204,8 @@ class USER_BACKEND_MANAGER extends USER_BACKEND {
return userData;
}
async getAllUsers (params = null) {}
async setUser (user, attributes, params = null) {
const results = {
ok: true,
@ -213,6 +229,8 @@ class USER_BACKEND_MANAGER extends USER_BACKEND {
getGroup (group, params = null) {}
getAllGroups (params = null) {}
setGroup (group, attributes, params = null) {}
delGroup (group, params = null) {}

View File

@ -3,6 +3,8 @@ export const router = Router({ mergeParams: true }); ;
const checkAuth = global.utils.checkAuth;
global.utils.recursiveImportRoutes(router, "/access", "access", import.meta.url);
/**
* GET - check authentication
* responses:

View File

@ -0,0 +1,16 @@
import { Router } from "express";
export const router = Router({ mergeParams: true });
/**
* GET - get all groups
* responses:
* - 200: {auth:true, groups: Array}
* - 201: {auth: false}
*/
router.get("/", async (req, res) => {
const auth = await checkAuth(req.cookies, res);
if (!auth) {
return;
}
res.status(200).send(global.userManager.getAllGroups())
});

View File

@ -0,0 +1,16 @@
import { Router } from "express";
export const router = Router({ mergeParams: true });
/**
* GET - get all users
* responses:
* - 200: {auth:true, users: Array}
* - 201: {auth: false}
*/
router.get("/", async (req, res) => {
const auth = await checkAuth(req.cookies, res);
if (!auth) {
return;
}
res.status(200).send(global.userManager.getAllUsers())
});