add accounts api route and page

This commit is contained in:
Linus Miller 2025-11-27 22:29:41 +01:00
parent ac61674b69
commit abc561258a
5 changed files with 85 additions and 1 deletions

View File

@ -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
}

View File

@ -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 (
<section>
<Head>
<title> : Accounts</title>
</Head>
<h1>Accounts</h1>
<table>
<thead>
<th>Number</th>
<th>Description</th>
</thead>
<tbody>
{accounts.map((account) => (
<tr>
<td>{account.number}</td>
<td>{account.description}</td>
</tr>
))}
</tbody>
</table>
</section>
)
}
export default AccountsPage

View File

@ -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',

View File

@ -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<typeof FinancialYear>
const apiRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
fastify.register(accounts, { prefix: '/accounts' })
fastify.route({
url: '/financial-years',
method: 'GET',

View File

@ -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