21 lines
662 B
TypeScript
21 lines
662 B
TypeScript
import { Handlers } from "$fresh/server.ts";
|
|
import { db } from "../../../db/db.ts";
|
|
|
|
export const handler: Handlers = {
|
|
async GET(req, _ctx): Promise<Response> {
|
|
const headers = new Headers({
|
|
"content-type": "application/json"
|
|
});
|
|
const url = new URL(req.url);
|
|
const q = url.searchParams.get("q");
|
|
const name = url.searchParams.get("name");
|
|
const corps = await db.selectFrom("KRXCorp")
|
|
.selectAll([
|
|
"KRXCorp"
|
|
])
|
|
.$if(!!q, qb=> qb.where("Name", "like", "%"+q+"%"))
|
|
.$if(!!name, qb => qb.where("Name", "=", name))
|
|
.execute();
|
|
return new Response(JSON.stringify(corps), {headers});
|
|
},
|
|
} |