From 5c75af9aaa2b6eed0389987eb7302fd2433a27ef Mon Sep 17 00:00:00 2001 From: Linus Miller Date: Mon, 24 Nov 2025 23:07:31 +0100 Subject: [PATCH] create objects page and routes --- .bruno/BRF/Object.bru | 16 +++++++++ .bruno/BRF/Objects.bru | 16 +++++++++ .bruno/BRF/Result.bru | 2 +- .bruno/BRF/Results.bru | 2 +- .gitignore | 1 + client/public/components/object.tsx | 31 +++++++++++++++++ client/public/components/objects_page.tsx | 41 +++++++++++++++++++++++ client/public/routes.ts | 7 ++++ server/routes/api.ts | 39 +++++++++++++++++++++ 9 files changed, 153 insertions(+), 2 deletions(-) create mode 100644 .bruno/BRF/Object.bru create mode 100644 .bruno/BRF/Objects.bru create mode 100644 client/public/components/object.tsx create mode 100644 client/public/components/objects_page.tsx diff --git a/.bruno/BRF/Object.bru b/.bruno/BRF/Object.bru new file mode 100644 index 0000000..dbcfd84 --- /dev/null +++ b/.bruno/BRF/Object.bru @@ -0,0 +1,16 @@ +meta { + name: Object + type: http + seq: 3 +} + +get { + url: {{base_url}}/api/objects/10 + body: none + auth: inherit +} + +settings { + encodeUrl: true + timeout: 0 +} diff --git a/.bruno/BRF/Objects.bru b/.bruno/BRF/Objects.bru new file mode 100644 index 0000000..c7f9678 --- /dev/null +++ b/.bruno/BRF/Objects.bru @@ -0,0 +1,16 @@ +meta { + name: Objects + type: http + seq: 4 +} + +get { + url: {{base_url}}/api/objects + body: none + auth: inherit +} + +settings { + encodeUrl: true + timeout: 0 +} diff --git a/.bruno/BRF/Result.bru b/.bruno/BRF/Result.bru index e9f9203..bf0cafa 100644 --- a/.bruno/BRF/Result.bru +++ b/.bruno/BRF/Result.bru @@ -1,7 +1,7 @@ meta { name: Result type: http - seq: 2 + seq: 5 } get { diff --git a/.bruno/BRF/Results.bru b/.bruno/BRF/Results.bru index b3d8eb2..c5c2f6a 100644 --- a/.bruno/BRF/Results.bru +++ b/.bruno/BRF/Results.bru @@ -1,7 +1,7 @@ meta { name: Results type: http - seq: 4 + seq: 6 } get { diff --git a/.gitignore b/.gitignore index 9f60d3c..1f85697 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /dump +/sie # Logs logs diff --git a/client/public/components/object.tsx b/client/public/components/object.tsx new file mode 100644 index 0000000..d24b80f --- /dev/null +++ b/client/public/components/object.tsx @@ -0,0 +1,31 @@ +import { h, type FunctionalComponent } from 'preact' +import { useEffect, useState } from 'preact/hooks' +import rek from 'rek' + +interface Props { + objectId: number +} + +const Result: FunctionalComponent = ({ objectId }) => { + const [transactions, setTransactions] = useState([]) + + useEffect(() => { + rek(`/api/objects/${objectId}`).then(setTransactions) + }, [objectId]) + + return ( + + + {transactions.map((transaction) => ( + + + + + + ))} + +
{transaction.transactionDate.slice(0, 10)}{transaction.accountNumber}{transaction.amount}
+ ) +} + +export default Result diff --git a/client/public/components/objects_page.tsx b/client/public/components/objects_page.tsx new file mode 100644 index 0000000..2906ea3 --- /dev/null +++ b/client/public/components/objects_page.tsx @@ -0,0 +1,41 @@ +import { h } from 'preact' +import { useEffect, useState } from 'preact/hooks' +import rek from 'rek' +import Head from './head.ts' +import Object from './object.tsx' +import s from './results_page.module.scss' + +const ObjectsPage = () => { + const [objects, setObjects] = useState([]) + const [currentObject, setCurrentObject] = useState(null) + + useEffect(() => { + rek('/api/objects').then(setObjects) + }, []) + + return ( +
+ + : Objects + + +

Objects

+
+ {objects.map((object) => ( + + ))} +
+ + {currentObject ? ( +
+

{currentObject}

+ + + ) : null} + + ) +} + +export default ObjectsPage diff --git a/client/public/routes.ts b/client/public/routes.ts index c47c16d..05c78c3 100644 --- a/client/public/routes.ts +++ b/client/public/routes.ts @@ -1,4 +1,5 @@ import Start from './components/start_page.tsx' +import Objects from './components/objects_page.tsx' import Results from './components/results_page.tsx' export default [ @@ -8,6 +9,12 @@ export default [ title: 'Start', component: Start, }, + { + path: '/objects', + name: 'objects', + title: 'Objects', + component: Objects, + }, { path: '/results', name: 'results', diff --git a/server/routes/api.ts b/server/routes/api.ts index 4e8bd6b..3c68150 100644 --- a/server/routes/api.ts +++ b/server/routes/api.ts @@ -1,5 +1,6 @@ import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' import knex from '../lib/knex.ts' +import StatusError from '../lib/status_error.ts' export const FinancialYear = Type.Object({ year: Type.Number(), @@ -18,6 +19,44 @@ const apiRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { }, }) + fastify.route({ + url: '/objects', + method: 'GET', + handler() { + return knex('object AS o') + .select('o.id', 'o.number', 'o.name', 'd.number AS dimensionNumber', 'd.name AS dimensionName') + .innerJoin('dimension AS d', function () { + this.on('o.dimensionId', '=', 'd.id') + }) + }, + }) + + fastify.route({ + url: '/objects/:id', + method: 'GET', + schema: { + params: Type.Object({ + id: Type.Number(), + }), + }, + async handler(req) { + // const object = knex('object').first('*').where('id', req.params.id) + + // if (!object) throw new StatusError(404) + console.log(req.params.id) + + return knex('transaction AS t') + .select('e.transactionDate', 't.accountNumber', 't.amount') + .innerJoin('transactions_to_objects AS to', function () { + this.on('t.id', 'to.transactionId') + }) + .innerJoin('entry AS e', function () { + this.on('e.id', '=', 't.entryId') + }) + .where('to.objectId', req.params.id) + }, + }) + fastify.route({ url: '/results', method: 'GET',