UNPKG

autumn-js

Version:
79 lines (76 loc) 1.76 kB
import { withAuth } from "./chunk-UJBSJTAV.mjs"; // src/libraries/backend/routes/entityRoutes.ts import { addRoute } from "rou3"; var createEntityHandler = (options) => withAuth({ fn: async ({ autumn, customer_id, body }) => { return await autumn.entities.create(customer_id, body); }, suppressLogs: options?.suppressLogs }); var getEntityHandler = (options) => withAuth({ fn: async ({ autumn, customer_id, pathParams, searchParams }) => { if (!pathParams?.entityId) { return { statusCode: 400, body: { error: "no_entity_id", message: "Entity ID is required" } }; } let params = { expand: searchParams?.expand?.split(",") }; let res = await autumn.entities.get( customer_id, pathParams.entityId, params ); return res; }, suppressLogs: options?.suppressLogs }); var deleteEntityHandler = (options) => withAuth({ fn: async ({ autumn, customer_id, pathParams }) => { if (!pathParams?.entityId) { return { statusCode: 400, body: { error: "no_entity_id", message: "Entity ID is required" } }; } return await autumn.entities.delete(customer_id, pathParams.entityId); }, suppressLogs: options?.suppressLogs }); var addEntityRoutes = async (router, options) => { addRoute(router, "POST", "/api/autumn/entities", { handler: createEntityHandler(options) }); addRoute(router, "GET", "/api/autumn/entities/:entityId", { handler: getEntityHandler(options) }); addRoute(router, "DELETE", "/api/autumn/entities/:entityId", { handler: deleteEntityHandler(options) }); }; export { addEntityRoutes };