add accounts api route and page
This commit is contained in:
parent
ac61674b69
commit
abc561258a
15
.bruno/BRF/api-accounts.bru
Normal file
15
.bruno/BRF/api-accounts.bru
Normal 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
|
||||||
|
}
|
||||||
41
client/public/components/accounts_page.tsx
Normal file
41
client/public/components/accounts_page.tsx
Normal 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
|
||||||
@ -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 Invoices from './components/invoices_page.tsx'
|
||||||
import InvoicesBySupplier from './components/invoices_by_supplier_page.tsx'
|
import InvoicesBySupplier from './components/invoices_by_supplier_page.tsx'
|
||||||
import Objects from './components/objects_page.tsx'
|
import Objects from './components/objects_page.tsx'
|
||||||
import Results from './components/results_page.tsx'
|
import Results from './components/results_page.tsx'
|
||||||
|
import Start from './components/start_page.tsx'
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
{
|
{
|
||||||
@ -11,6 +12,12 @@ export default [
|
|||||||
title: 'Start',
|
title: 'Start',
|
||||||
component: Start,
|
component: Start,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/accounts',
|
||||||
|
name: 'accounts',
|
||||||
|
title: 'Accounts',
|
||||||
|
component: Accounts,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/objects',
|
path: '/objects',
|
||||||
name: 'objects',
|
name: 'objects',
|
||||||
|
|||||||
@ -3,6 +3,8 @@ import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/t
|
|||||||
import knex from '../lib/knex.ts'
|
import knex from '../lib/knex.ts'
|
||||||
import StatusError from '../lib/status_error.ts'
|
import StatusError from '../lib/status_error.ts'
|
||||||
|
|
||||||
|
import accounts from './api/accounts.ts'
|
||||||
|
|
||||||
export const FinancialYear = Type.Object({
|
export const FinancialYear = Type.Object({
|
||||||
year: Type.Number(),
|
year: Type.Number(),
|
||||||
startDate: Type.String(),
|
startDate: Type.String(),
|
||||||
@ -12,6 +14,8 @@ export const FinancialYear = Type.Object({
|
|||||||
export type FinancialYearType = Static<typeof FinancialYear>
|
export type FinancialYearType = Static<typeof FinancialYear>
|
||||||
|
|
||||||
const apiRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
|
const apiRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
|
||||||
|
fastify.register(accounts, { prefix: '/accounts' })
|
||||||
|
|
||||||
fastify.route({
|
fastify.route({
|
||||||
url: '/financial-years',
|
url: '/financial-years',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
|||||||
17
server/routes/api/accounts.ts
Normal file
17
server/routes/api/accounts.ts
Normal 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
|
||||||
Loading…
Reference in New Issue
Block a user