journal work

This commit is contained in:
Michael Zhang 2024-07-26 21:48:51 -05:00
parent 3958e1cc3d
commit ada06b06df
9 changed files with 69 additions and 5 deletions

1
apps/journal/.gitignore vendored Normal file
View file

@ -0,0 +1 @@
index.js

BIN
apps/journal/bun.lockb Executable file

Binary file not shown.

41
apps/journal/index.ts Normal file
View file

@ -0,0 +1,41 @@
import type { Context } from "koa";
import { formatDate } from "date-fns";
import { uuidv7 } from "uuidv7";
export async function today(ctx: Context) {
const date = new Date();
const day = formatDate(date, "P");
const resp = await fetch("http://localhost:3000/node/sql", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: `
select * from node_has_attribute as na
join attribute as a on na.attrName = a.name
where a.name = 'day' and na.string = '${day}';
`,
parameters: [],
}),
});
const { rows } = await resp.json();
if (rows.length === 0) {
const id = uuidv7();
const resp = await fetch("http://localhost:3000/node/sql", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: `
begin transaction;
insert into node (id) values (?);
end transaction;
`,
parameters: [id],
}),
});
const data = await resp.json();
console.log("Result", data);
}
ctx.body = {};
}

10
apps/journal/manifest.yml Normal file
View file

@ -0,0 +1,10 @@
name: panorama/journal
code: index.js
attributes:
- name: day
type: Option<String>
endpoints:
- route: /today
handler: today

View file

@ -0,0 +1,9 @@
{
"dependencies": {
"date-fns": "^3.6.0",
"koa": "^2.15.3"
},
"devDependencies": {
"@types/koa": "^2.15.0"
}
}

Binary file not shown.

View file

@ -75,7 +75,13 @@ nodeRouter.put("/", async (ctx) => {
ctx.body = { id };
});
nodeRouter.post("/query", async (ctx) => {});
// TODO: WILL BE REMOVED BEFORE ALPHA RELEASE
nodeRouter.post("/sql", async (ctx) => {
const body = ctx.request.body;
const { query, parameters } = body;
const rows = await dataSource.query(query, parameters ?? []);
ctx.body = { rows };
});
nodeRouter.get("/recent", async (ctx) => {
const result = await dataSource.query<NodeHasAttribute[]>(`

View file

@ -19,8 +19,6 @@ const queryClient = new QueryClient();
TimeAgo.addDefaultLocale(en);
// export const nodesOpenedAtom = atom<OrderedSet<string>>(OrderedSet<string>());
function App() {
const panelsOpened = useAtomValue(panelsOpenedAtom);
const { openNode } = usePanelControls();
@ -31,7 +29,7 @@ function App() {
if (panelsOpened.size === 0) {
console.log("Opening today's entry.");
const resp = await fetch(
`${PANORAMA_DAEMON_URL}/journal/get_todays_journal_id`,
`${PANORAMA_DAEMON_URL}/apps/panorama__journal/today`,
);
const data = await resp.json();
console.log("resp", data);

View file

@ -11,7 +11,6 @@ import {
} from "@floating-ui/react";
import { useCallback, useEffect, useState } from "react";
import { atom, useAtom, useSetAtom } from "jotai";
import { useDebounce, useDebouncedCallback } from "use-debounce";
import { usePanelControls } from "../lib/panelManagement";
const searchQueryAtom = atom("");