made pretty and fixed message posting

This commit is contained in:
Kevin Puig
2025-09-27 15:55:20 -04:00
parent 74f4e076ce
commit da1310b9c8
10 changed files with 415 additions and 390 deletions

View File

@@ -1,28 +1,29 @@
import { Hono } from "hono";
import { zValidator } from "@hono/zod-validator";
import { describeRoute, resolver } from "hono-openapi";
import { postMessageToChannel,
deleteMessageFromChannel
import {
postMessageToChannel,
deleteMessageFromChannel,
} from "../controller/realtime";
const app = new Hono();
app.post(
"message/",
zValidator({
body: z.object({
content: z.string().min(1).max(500)
})
"message/",
zValidator({
body: z.object({
content: z.string().min(1).max(500),
}),
async (c) => {
const { instanceId, categoryId, channelId } = c.req.params;
const { content } = c.req.body;
}),
async (c) => {
const { instanceId, categoryId, channelId } = c.req.params;
const { content } = c.req.body;
return postMessageToChannel(c.get("io"), {
instanceId,
categoryId,
channelId,
content
});
}
);
return postMessageToChannel(c.get("io"), {
instanceId,
categoryId,
channelId,
content,
});
},
);

View File

@@ -1,29 +1,38 @@
import { Hono } from "hono";
import { fetchAllUsers, fetchUserData, createNewUser } from "../controller/userController";
import { createUserSchema, queryAllUsersByInstanceId, queryUserByIdSchema } from "../validators/userValidator";
import {
fetchAllUsers,
fetchUserData,
createNewUser,
} from "../controller/userController";
import {
createUserSchema,
queryAllUsersByInstanceId,
queryUserByIdSchema,
} from "../validators/userValidator";
import { zValidator } from "@hono/zod-validator";
import { describeRoute, resolver } from "hono-openapi";
const actions = new Hono();
actions.get("user/:id",
actions.get(
"user/:id",
describeRoute({
description: "Get user by id",
responses: {
200: {
description: "Success getting user",
content: {
"application/json": { schema: resolver(queryUserByIdSchema) }
}
"application/json": { schema: resolver(queryUserByIdSchema) },
},
},
404: {
description: "User id not found",
content: {
"application/json": { schema: resolver(queryUserByIdSchema) }
}
}
}
"application/json": { schema: resolver(queryUserByIdSchema) },
},
},
},
}),
zValidator('param', queryUserByIdSchema),
zValidator("param", queryUserByIdSchema),
async (c) => {
const id = c.req.param("id");
const userData = await fetchUserData(id);
@@ -32,22 +41,23 @@ actions.get("user/:id",
} else {
return c.json({ error: "User not found" }, 404);
}
}
},
);
actions.get("user",
actions.get(
"user",
describeRoute({
description: "Get all users by instance id",
responses: {
200: {
description: "Success getting all users in instance",
content: {
"application/json": { schema: resolver(queryAllUsersByInstanceId) }
}
}
}
"application/json": { schema: resolver(queryAllUsersByInstanceId) },
},
},
},
}),
zValidator('query', queryAllUsersByInstanceId),
zValidator("query", queryAllUsersByInstanceId),
async (c) => {
const instanceId = c.req.query("instanceId");
if (!instanceId) {
@@ -60,7 +70,7 @@ actions.get("user",
} else {
return c.json({ error: "Error getting all users from instance" }, 500);
}
}
},
);
actions.post(
@@ -71,18 +81,18 @@ actions.post(
201: {
description: "Success",
content: {
'application/json': { schema: resolver(createUserSchema) },
"application/json": { schema: resolver(createUserSchema) },
},
},
400: {
description: "Bad request (user exists)",
content: {
'application/json': { schema: resolver(createUserSchema) }
}
}
}
"application/json": { schema: resolver(createUserSchema) },
},
},
},
}),
zValidator('json', createUserSchema),
zValidator("json", createUserSchema),
async (c) => {
try {
const data = await c.req.json();
@@ -94,7 +104,7 @@ actions.post(
} catch (error) {
return c.json({ error: "Error creating user" }, 500);
}
}
},
);
export default actions;