modules/0-ui

This commit is contained in:
Lucas Tettamanti
2026-01-15 22:53:37 -03:00
parent ea62385e3d
commit 98e3d78e3d
17 changed files with 17 additions and 23 deletions

View File

@@ -0,0 +1,47 @@
import { handleDeleteConversation, handleDeleteUser, handleListUsers, handleRetryLast } from "../handlers/admin.js";
export const makeDeleteConversation = (tenantIdOrFn) => async (req, res) => {
try {
const tenantId = typeof tenantIdOrFn === "function" ? tenantIdOrFn() : tenantIdOrFn;
const result = await handleDeleteConversation({ tenantId, chat_id: req.params.chat_id });
res.json(result);
} catch (err) {
console.error(err);
res.status(500).json({ ok: false, error: "internal_error" });
}
};
export const makeListUsers = (tenantIdOrFn) => async (req, res) => {
try {
const tenantId = typeof tenantIdOrFn === "function" ? tenantIdOrFn() : tenantIdOrFn;
const result = await handleListUsers({ tenantId, q: req.query.q || "", limit: req.query.limit || "200" });
res.json(result);
} catch (err) {
console.error(err);
res.status(500).json({ ok: false, error: "internal_error" });
}
};
export const makeDeleteUser = (tenantIdOrFn) => async (req, res) => {
try {
const tenantId = typeof tenantIdOrFn === "function" ? tenantIdOrFn() : tenantIdOrFn;
const deleteWoo = String(req.query.deleteWoo || "0") === "1" || String(req.query.deleteWoo || "").toLowerCase() === "true";
const result = await handleDeleteUser({ tenantId, chat_id: req.params.chat_id, deleteWoo });
res.json(result);
} catch (err) {
console.error(err);
res.status(500).json({ ok: false, error: "internal_error" });
}
};
export const makeRetryLast = (tenantIdOrFn) => async (req, res) => {
try {
const tenantId = typeof tenantIdOrFn === "function" ? tenantIdOrFn() : tenantIdOrFn;
const result = await handleRetryLast({ tenantId, chat_id: req.params.chat_id });
res.json(result);
} catch (err) {
console.error(err);
res.status(500).json({ ok: false, error: "internal_error" });
}
};

View File

@@ -0,0 +1,16 @@
import { handleGetConversationState } from "../handlers/conversationState.js";
export const makeGetConversationState = (tenantIdOrFn) => async (req, res) => {
try {
const tenantId = typeof tenantIdOrFn === "function" ? tenantIdOrFn() : tenantIdOrFn;
const { status, payload } = await handleGetConversationState({
tenantId,
chat_id: req.query.chat_id || null,
});
res.status(status).json(payload);
} catch (err) {
console.error(err);
res.status(500).json({ ok: false, error: "internal_error" });
}
};

View File

@@ -0,0 +1,13 @@
import { handleListConversations } from "../handlers/conversations.js";
export const makeGetConversations = (tenantIdOrFn) => async (req, res) => {
try {
const tenantId = typeof tenantIdOrFn === "function" ? tenantIdOrFn() : tenantIdOrFn;
const items = await handleListConversations({ tenantId, query: req.query });
res.json({ items });
} catch (err) {
console.error(err);
res.status(500).json({ ok: false, error: "internal_error" });
}
};

View File

@@ -0,0 +1,17 @@
import { handleListMessages } from "../handlers/messages.js";
export const makeListMessages = (tenantIdOrFn) => async (req, res) => {
try {
const tenantId = typeof tenantIdOrFn === "function" ? tenantIdOrFn() : tenantIdOrFn;
const items = await handleListMessages({
tenantId,
chat_id: req.query.chat_id || null,
limit: req.query.limit || "200",
});
res.json({ items });
} catch (err) {
console.error(err);
res.status(500).json({ ok: false, error: "internal_error" });
}
};

View File

@@ -0,0 +1,16 @@
import { handleSearchProducts } from "../handlers/products.js";
export const makeSearchProducts = (tenantIdOrFn) => async (req, res) => {
try {
const tenantId = typeof tenantIdOrFn === "function" ? tenantIdOrFn() : tenantIdOrFn;
const q = req.query.q || "";
const limit = req.query.limit || "10";
const forceWoo = req.query.forceWoo || "0";
const result = await handleSearchProducts({ tenantId, q, limit, forceWoo });
res.json(result);
} catch (err) {
console.error(err);
res.status(500).json({ ok: false, error: "internal_error" });
}
};

View File

@@ -0,0 +1,29 @@
import { handleListRuns, handleGetRun } from "../handlers/runs.js";
export const makeListRuns = (tenantIdOrFn) => async (req, res) => {
try {
const tenantId = typeof tenantIdOrFn === "function" ? tenantIdOrFn() : tenantIdOrFn;
const items = await handleListRuns({
tenantId,
chat_id: req.query.chat_id || null,
limit: req.query.limit || "50",
});
res.json({ items });
} catch (err) {
console.error(err);
res.status(500).json({ ok: false, error: "internal_error" });
}
};
export const makeGetRunById = (tenantIdOrFn) => async (req, res) => {
try {
const tenantId = typeof tenantIdOrFn === "function" ? tenantIdOrFn() : tenantIdOrFn;
const run = await handleGetRun({ tenantId, run_id: req.params.run_id });
if (!run) return res.status(404).json({ ok: false, error: "not_found" });
res.json(run);
} catch (err) {
console.error(err);
res.status(500).json({ ok: false, error: "internal_error" });
}
};