journal work
This commit is contained in:
parent
3958e1cc3d
commit
ada06b06df
9 changed files with 69 additions and 5 deletions
1
apps/journal/.gitignore
vendored
Normal file
1
apps/journal/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
index.js
|
BIN
apps/journal/bun.lockb
Executable file
BIN
apps/journal/bun.lockb
Executable file
Binary file not shown.
41
apps/journal/index.ts
Normal file
41
apps/journal/index.ts
Normal 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
10
apps/journal/manifest.yml
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
name: panorama/journal
|
||||||
|
code: index.js
|
||||||
|
|
||||||
|
attributes:
|
||||||
|
- name: day
|
||||||
|
type: Option<String>
|
||||||
|
|
||||||
|
endpoints:
|
||||||
|
- route: /today
|
||||||
|
handler: today
|
9
apps/journal/package.json
Normal file
9
apps/journal/package.json
Normal 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.
|
@ -75,7 +75,13 @@ nodeRouter.put("/", async (ctx) => {
|
||||||
ctx.body = { id };
|
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) => {
|
nodeRouter.get("/recent", async (ctx) => {
|
||||||
const result = await dataSource.query<NodeHasAttribute[]>(`
|
const result = await dataSource.query<NodeHasAttribute[]>(`
|
||||||
|
|
|
@ -19,8 +19,6 @@ const queryClient = new QueryClient();
|
||||||
|
|
||||||
TimeAgo.addDefaultLocale(en);
|
TimeAgo.addDefaultLocale(en);
|
||||||
|
|
||||||
// export const nodesOpenedAtom = atom<OrderedSet<string>>(OrderedSet<string>());
|
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
const panelsOpened = useAtomValue(panelsOpenedAtom);
|
const panelsOpened = useAtomValue(panelsOpenedAtom);
|
||||||
const { openNode } = usePanelControls();
|
const { openNode } = usePanelControls();
|
||||||
|
@ -31,7 +29,7 @@ function App() {
|
||||||
if (panelsOpened.size === 0) {
|
if (panelsOpened.size === 0) {
|
||||||
console.log("Opening today's entry.");
|
console.log("Opening today's entry.");
|
||||||
const resp = await fetch(
|
const resp = await fetch(
|
||||||
`${PANORAMA_DAEMON_URL}/journal/get_todays_journal_id`,
|
`${PANORAMA_DAEMON_URL}/apps/panorama__journal/today`,
|
||||||
);
|
);
|
||||||
const data = await resp.json();
|
const data = await resp.json();
|
||||||
console.log("resp", data);
|
console.log("resp", data);
|
||||||
|
|
|
@ -11,7 +11,6 @@ import {
|
||||||
} from "@floating-ui/react";
|
} from "@floating-ui/react";
|
||||||
import { useCallback, useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import { atom, useAtom, useSetAtom } from "jotai";
|
import { atom, useAtom, useSetAtom } from "jotai";
|
||||||
import { useDebounce, useDebouncedCallback } from "use-debounce";
|
|
||||||
import { usePanelControls } from "../lib/panelManagement";
|
import { usePanelControls } from "../lib/panelManagement";
|
||||||
|
|
||||||
const searchQueryAtom = atom("");
|
const searchQueryAtom = atom("");
|
||||||
|
|
Loading…
Reference in a new issue