35 lines
928 B
TypeScript
35 lines
928 B
TypeScript
import { Handlers } from "$fresh/server.ts";
|
|
import { db } from "../../../db/db.ts";
|
|
import { jsonArrayFrom } from "kysely/helpers/sqlite";
|
|
|
|
export const handler: Handlers = {
|
|
async GET(req, ctx): Promise<Response> {
|
|
const headers = new Headers({
|
|
"content-type": "application/json"
|
|
});
|
|
const index = ctx.params.index;
|
|
const corp = await db.selectFrom("KRXCorp")
|
|
.selectAll([
|
|
"KRXCorp"
|
|
])
|
|
.select(eb=> [
|
|
jsonArrayFrom(eb.selectFrom("stock")
|
|
.select([
|
|
"stock.Close",
|
|
"stock.Open",
|
|
"stock.Low",
|
|
"stock.High",
|
|
"stock.Date",
|
|
"stock.Volume",
|
|
])
|
|
.where("Code", "=", index)
|
|
.orderBy("Date", "desc")
|
|
.limit(100)
|
|
).as("prices")]
|
|
)
|
|
.where("Code", "=", index)
|
|
.executeTakeFirst();
|
|
|
|
return new Response(JSON.stringify(corp ?? null), {headers});
|
|
},
|
|
} |