modules/0-ui
This commit is contained in:
47
src/modules/0-ui/controllers/admin.js
Normal file
47
src/modules/0-ui/controllers/admin.js
Normal 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" });
|
||||
}
|
||||
};
|
||||
|
||||
16
src/modules/0-ui/controllers/conversationState.js
Normal file
16
src/modules/0-ui/controllers/conversationState.js
Normal 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" });
|
||||
}
|
||||
};
|
||||
|
||||
13
src/modules/0-ui/controllers/conversations.js
Normal file
13
src/modules/0-ui/controllers/conversations.js
Normal 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" });
|
||||
}
|
||||
};
|
||||
|
||||
17
src/modules/0-ui/controllers/messages.js
Normal file
17
src/modules/0-ui/controllers/messages.js
Normal 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" });
|
||||
}
|
||||
};
|
||||
|
||||
16
src/modules/0-ui/controllers/products.js
Normal file
16
src/modules/0-ui/controllers/products.js
Normal 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" });
|
||||
}
|
||||
};
|
||||
|
||||
29
src/modules/0-ui/controllers/runs.js
Normal file
29
src/modules/0-ui/controllers/runs.js
Normal 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" });
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user