42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import {NextRequest, NextResponse} from "next/server";
|
|
import {RouteContext} from "@/types/common";
|
|
import {createIntranetApi} from "@/lib/http-server";
|
|
import {CallerTelNumInfo, IntranetProjectSearchResponse} from "@/types/project";
|
|
import {errorToResponse} from "@kri/common/http";
|
|
import {ItrntUserInfo} from "@/types/user";
|
|
|
|
export const GET = async (req: NextRequest, context: RouteContext) => {
|
|
try {
|
|
const { searchParams } = new URL(req.url);
|
|
const {slug = []} = await context.params;
|
|
const [action] = slug;
|
|
const itrntApi = await createIntranetApi();
|
|
|
|
if(action === "project"){
|
|
const keyword = (searchParams.get("keyword") ?? "").trim();
|
|
const result = await itrntApi.get<IntranetProjectSearchResponse[]>(
|
|
`/project/search/top10`,
|
|
{ query: keyword ? { keyword } : {} }
|
|
);
|
|
|
|
return NextResponse.json(result, { status: 200 });
|
|
}
|
|
|
|
if(action === "user-list"){
|
|
const result = await itrntApi.get<ItrntUserInfo[]>(`/user/list`);
|
|
|
|
return NextResponse.json(result, { status: 200 });
|
|
}
|
|
|
|
if(action === "caller-tel-num"){
|
|
const result = await itrntApi.get<CallerTelNumInfo[]>(`/telnum/caller`);
|
|
|
|
return NextResponse.json(result, { status: 200 });
|
|
}
|
|
|
|
return NextResponse.json({ message: "Not found" }, { status: 404 });
|
|
} catch (error: unknown) {
|
|
return errorToResponse(error);
|
|
}
|
|
};
|