From f193963a2bc3c50350b592a0b20815a064a45b3f Mon Sep 17 00:00:00 2001 From: Marius Obert Date: Tue, 5 Nov 2024 16:24:59 +0100 Subject: [PATCH] fix migration issues --- .../orders/broadcast-popover-content.tsx | 1 - src/app/api/broadcast/route.ts | 51 ------------------- src/app/api/event/route.ts | 3 +- src/app/api/order/route.ts | 5 +- 4 files changed, 3 insertions(+), 57 deletions(-) delete mode 100644 src/app/api/broadcast/route.ts diff --git a/src/app/(master-layout)/event/[slug]/orders/broadcast-popover-content.tsx b/src/app/(master-layout)/event/[slug]/orders/broadcast-popover-content.tsx index bfdc263..39b985e 100644 --- a/src/app/(master-layout)/event/[slug]/orders/broadcast-popover-content.tsx +++ b/src/app/(master-layout)/event/[slug]/orders/broadcast-popover-content.tsx @@ -41,7 +41,6 @@ export default function BroadcastPopoverContent({ "Content-Type": "application/json", }, body: JSON.stringify({ - event: eventSlug, message, }), }).then((res) => { diff --git a/src/app/api/broadcast/route.ts b/src/app/api/broadcast/route.ts deleted file mode 100644 index 3104687..0000000 --- a/src/app/api/broadcast/route.ts +++ /dev/null @@ -1,51 +0,0 @@ -import { headers } from "next/headers"; - -import { fetchSyncListItems, addMessageToConversation } from "@/lib/twilio"; -import { Privilege, getAuthenticatedRole } from "@/middleware"; - -export async function POST(request: Request) { - const [headersList, json] = await Promise.all([headers(), request.json()]); - const { message, event } = json; - const role = getAuthenticatedRole(headersList.get("Authorization") || ""); - - const hasPermissions = - Privilege.ADMIN === role || Privilege.MIXOLOGIST === role; - if ( - !process.env.NEXT_PUBLIC_EVENTS_MAP || - !process.env.NEXT_PUBLIC_ACTIVE_CUSTOMERS_MAP - ) { - console.error("No config doc specified"); - return new Response("No config doc specified", { - status: 500, - statusText: "No config doc specified", - }); - } - if (!hasPermissions) { - console.error("Not authorized"); - return new Response( - `Role ${role} is not authorized to perform this action`, - { - status: 500, - statusText: `Role ${role} is not authorized to perform this action`, - }, - ); - } - - try { - const listItems = await fetchSyncListItems(event); - const queuedOrders = listItems.filter( - (listItem) => - (listItem.data?.status === "queued" || - listItem.data?.status === "ready") && - !listItem.data?.manual, - ); - - queuedOrders.forEach((order) => { - addMessageToConversation(order.data.key, message); - }); - return new Response(null, { status: 201 }); - } catch (e: any) { - console.error(e); - return new Response(e.message, { status: 500, statusText: e.message }); - } -} diff --git a/src/app/api/event/route.ts b/src/app/api/event/route.ts index 778df6e..7afcb1a 100644 --- a/src/app/api/event/route.ts +++ b/src/app/api/event/route.ts @@ -8,8 +8,7 @@ import { Privilege, getAuthenticatedRole } from "@/middleware"; import { revalidatePath } from "next/cache"; export async function POST(request: Request) { - const [headersList, json] = await Promise.all([headers(), request.json()]); - const { event } = json; + const [headersList, event] = await Promise.all([headers(), request.json()]); const role = getAuthenticatedRole(headersList.get("Authorization") || ""); const isAdmin = Privilege.ADMIN === role; diff --git a/src/app/api/order/route.ts b/src/app/api/order/route.ts index 322ae98..92c0719 100644 --- a/src/app/api/order/route.ts +++ b/src/app/api/order/route.ts @@ -4,8 +4,7 @@ import { pushToSyncList } from "@/lib/twilio"; import { Privilege, getAuthenticatedRole } from "@/middleware"; export async function POST(request: Request) { - const [headersList, json] = await Promise.all([headers(), request.json()]); - const { data } = json; + const [headersList, data] = await Promise.all([headers(), request.json()]); const role = getAuthenticatedRole(headersList.get("Authorization") || ""); const isPrivileged = [ @@ -33,7 +32,7 @@ export async function POST(request: Request) { } try { - const newOrder = await pushToSyncList(data.event, data.order); + await pushToSyncList(data.event, data.order); } catch (e: any) { console.error(e); return new Response(e.message, { status: 500, statusText: e.message });