diff --git a/.bruno/BRF/api-accounts.bru b/.bruno/BRF/api-accounts.bru new file mode 100644 index 0000000..ae4a888 --- /dev/null +++ b/.bruno/BRF/api-accounts.bru @@ -0,0 +1,15 @@ +meta { + name: /api/accounts + type: http + seq: 9 +} + +get { + url: {{base_url}}/api/accounts + body: none + auth: inherit +} + +settings { + encodeUrl: true +} diff --git a/client/public/components/accounts_page.tsx b/client/public/components/accounts_page.tsx new file mode 100644 index 0000000..318df3f --- /dev/null +++ b/client/public/components/accounts_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 s from './accounts_page.module.scss' + +const AccountsPage = () => { + const [accounts, setAccounts] = useState([]) + + useEffect(() => { + rek('/api/accounts').then((accounts) => { + setAccounts(accounts) + }) + }, []) + + return ( +
+ + : Accounts + + +

Accounts

+ + + + + + + {accounts.map((account) => ( + + + + + ))} + +
NumberDescription
{account.number}{account.description}
+
+ ) +} + +export default AccountsPage diff --git a/client/public/routes.ts b/client/public/routes.ts index 6067436..983ce40 100644 --- a/client/public/routes.ts +++ b/client/public/routes.ts @@ -1,8 +1,9 @@ -import Start from './components/start_page.tsx' +import Accounts from './components/accounts_page.tsx' import Invoices from './components/invoices_page.tsx' import InvoicesBySupplier from './components/invoices_by_supplier_page.tsx' import Objects from './components/objects_page.tsx' import Results from './components/results_page.tsx' +import Start from './components/start_page.tsx' export default [ { @@ -11,6 +12,12 @@ export default [ title: 'Start', component: Start, }, + { + path: '/accounts', + name: 'accounts', + title: 'Accounts', + component: Accounts, + }, { path: '/objects', name: 'objects', diff --git a/server/routes/api.ts b/server/routes/api.ts index bf373d0..d5bce00 100644 --- a/server/routes/api.ts +++ b/server/routes/api.ts @@ -3,6 +3,8 @@ import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/t import knex from '../lib/knex.ts' import StatusError from '../lib/status_error.ts' +import accounts from './api/accounts.ts' + export const FinancialYear = Type.Object({ year: Type.Number(), startDate: Type.String(), @@ -12,6 +14,8 @@ export const FinancialYear = Type.Object({ export type FinancialYearType = Static const apiRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { + fastify.register(accounts, { prefix: '/accounts' }) + fastify.route({ url: '/financial-years', method: 'GET', diff --git a/server/routes/api/accounts.ts b/server/routes/api/accounts.ts new file mode 100644 index 0000000..ca66b6a --- /dev/null +++ b/server/routes/api/accounts.ts @@ -0,0 +1,17 @@ +import _ from 'lodash' +import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' +import knex from '../../lib/knex.ts' + +const apiRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { + fastify.route({ + url: '/', + method: 'GET', + handler() { + return knex('account').select('*').orderBy('number') + }, + }) + + done() +} + +export default apiRoutes