Created some user endpoints ; Pretty code
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
import { Hono } from "hono"
|
||||
import { fetchUserData } from "../controller/actions"
|
||||
const actions = new Hono()
|
||||
|
||||
/*
|
||||
actions.post("actions/message/:id", (c) => {
|
||||
//todo: pass service function to send a message to user id
|
||||
})
|
||||
|
||||
actions.delete("actions/message/delete/:id", (c) => {
|
||||
//todo: pass service function to delete a message by user id
|
||||
})
|
||||
|
||||
actions.get("actions/message/all/:userId", (c) => {
|
||||
//todo: pass service function to fetch all messages f a user
|
||||
})
|
||||
|
||||
|
||||
|
||||
actions.get("actions/userChannels/:id", (c) => {
|
||||
//todo: pass service function to fetch all channels the id is part of
|
||||
})
|
||||
*/
|
||||
|
||||
actions.get("actions/:id", async (c) => {
|
||||
const id = c.req.param("id");
|
||||
const userData = await fetchUserData(id);
|
||||
if (userData) {
|
||||
return c.json(userData);
|
||||
} else {
|
||||
return c.json({ error: "User not found" }, 404);
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
export default actions
|
||||
@@ -1,11 +1,9 @@
|
||||
//place exported routes below this line
|
||||
import { Hono } from 'hono';
|
||||
import actions from './actions';
|
||||
|
||||
import { Hono } from "hono";
|
||||
import actions from "./userRoutes";
|
||||
|
||||
const routes = new Hono();
|
||||
|
||||
routes.route("/", actions)
|
||||
routes.route("/", actions);
|
||||
|
||||
|
||||
export default routes;
|
||||
export default routes;
|
||||
|
||||
25
concord-server/src/routes/userRoutes.ts
Normal file
25
concord-server/src/routes/userRoutes.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
import { Hono } from "hono";
|
||||
import { fetchAllUsers, fetchUserData } from "../controller/userController";
|
||||
const actions = new Hono();
|
||||
|
||||
actions.get("user/:id", async (c) => {
|
||||
const id = c.req.param("id");
|
||||
const userData = await fetchUserData(id);
|
||||
if (userData) {
|
||||
return c.json(userData);
|
||||
} else {
|
||||
return c.json({ error: "User not found" }, 404);
|
||||
}
|
||||
});
|
||||
|
||||
actions.get("instance/:id/users", async (c) => {
|
||||
const instanceId = c.req.param("id");
|
||||
const userData = await fetchAllUsers(instanceId);
|
||||
if (userData) {
|
||||
return c.json(userData);
|
||||
} else {
|
||||
return c.json({ error: "Error getting all users from instance" }, 500);
|
||||
}
|
||||
});
|
||||
|
||||
export default actions;
|
||||
Reference in New Issue
Block a user