import {NextRequest, NextResponse} from "next/server"; import {RouteContext} from "@/types/common"; import {errorToResponse} from "@/lib/http-util"; import {createNotiHubApi} from "@/lib/server-api"; import { BulkSendResponse, CreateTemplateRequest, SaveTemplateRequest, SendSmsBulkRequest, Template, } from "@/types/notification"; export const GET = async ( _req: NextRequest, context: RouteContext ) => { try { const {slug = []} = await context.params; const [action, second, third, fourth] = slug; if (action !== "template") { return NextResponse.json({ message: "Not found" }, { status: 404 }); } const notiHubApi = await createNotiHubApi(); let path: string; if (second === "list") { if (slug.length !== 4 || !third || !fourth) { return NextResponse.json({ message: "Not found" }, { status: 404 }); } path = `/template/list/${encodeURIComponent(third)}/${encodeURIComponent(fourth)}`; } else { if (slug.length !== 2 || !second) { return NextResponse.json({ message: "Not found" }, { status: 404 }); } path = `/template/${encodeURIComponent(second)}`; } if (!path) { return NextResponse.json({ message: "Not found" }, { status: 404 }); } const template = await notiHubApi.get