Skip to content

Commit

Permalink
Removed get endpoint in messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
Luisotee committed Dec 29, 2024
1 parent 1568cba commit e59c509
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 122 deletions.
81 changes: 1 addition & 80 deletions apps/messaging/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import { swagger } from "@elysiajs/swagger";
import { Elysia } from "elysia";
import {
handleGetMessages,
handleHealthCheck,
handleSendMessage,
} from "./routes";
import { handleHealthCheck, handleSendMessage } from "./routes";
import { messageSchema } from "./types";

const PORT = process.env.PORT || 3000;
Expand Down Expand Up @@ -75,81 +71,6 @@ const app = new Elysia()
},
},
})
.get("/api/messages/receive", handleGetMessages, {
detail: {
tags: ["messages"],
description: "Get received messages",
parameters: [
{
in: "query",
name: "userId",
schema: { type: "string" },
required: false,
},
{
in: "query",
name: "limit",
schema: { type: "number" },
required: false,
},
{
in: "query",
name: "offset",
schema: { type: "number" },
required: false,
},
{
in: "query",
name: "platform",
schema: {
type: "string",
enum: ["whatsapp", "telegram", "simulator"],
},
required: false,
},
],
responses: {
"200": {
description: "Messages retrieved successfully",
content: {
"application/json": {
schema: {
type: "object",
properties: {
messages: {
type: "array",
items: {
type: "object",
properties: {
id: { type: "string" },
userId: { type: "string" },
text: { type: "string" },
platform: { type: "string" },
timestamp: { type: "number" },
},
},
},
},
},
},
},
},
"400": {
description: "Invalid request parameters",
content: {
"application/json": {
schema: {
type: "object",
properties: {
error: { type: "string" },
},
},
},
},
},
},
},
})
.get("/api/messages/health", handleHealthCheck, {
detail: {
tags: ["health"],
Expand Down
42 changes: 0 additions & 42 deletions apps/messaging/src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,48 +63,6 @@ export async function handleSendMessage(req: Request) {
}
}

export async function handleGetMessages(req: Request) {
try {
const url = new URL(req.url);
const params = queryParamsSchema.parse(
Object.fromEntries(url.searchParams),
);

let query = supabase
.from("received_messages")
.select("*")
.order("timestamp", { ascending: false });

if (params.userId) {
query = query.eq("user_id", params.userId);
}
if (params.limit) {
query = query.limit(params.limit);
}
if (params.offset) {
query = query.range(
params.offset,
params.offset + (params.limit || 10) - 1,
);
}
if (params.platform) {
query = query.eq("meta->platform", params.platform);
}

const { data, error } = await query;

if (error) throw error;

return Response.json({ messages: data });
} catch (error) {
logger.error("Error fetching messages", { error });
return Response.json(
{ error: "Failed to fetch messages" },
{ status: 400 },
);
}
}

export function handleHealthCheck() {
return Response.json({ status: "healthy" });
}

0 comments on commit e59c509

Please sign in to comment.