create objects page and routes
This commit is contained in:
parent
60bdd909a7
commit
5c75af9aaa
16
.bruno/BRF/Object.bru
Normal file
16
.bruno/BRF/Object.bru
Normal file
@ -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
|
||||||
|
}
|
||||||
16
.bruno/BRF/Objects.bru
Normal file
16
.bruno/BRF/Objects.bru
Normal file
@ -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
|
||||||
|
}
|
||||||
@ -1,7 +1,7 @@
|
|||||||
meta {
|
meta {
|
||||||
name: Result
|
name: Result
|
||||||
type: http
|
type: http
|
||||||
seq: 2
|
seq: 5
|
||||||
}
|
}
|
||||||
|
|
||||||
get {
|
get {
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
meta {
|
meta {
|
||||||
name: Results
|
name: Results
|
||||||
type: http
|
type: http
|
||||||
seq: 4
|
seq: 6
|
||||||
}
|
}
|
||||||
|
|
||||||
get {
|
get {
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
/dump
|
/dump
|
||||||
|
/sie
|
||||||
|
|
||||||
# Logs
|
# Logs
|
||||||
logs
|
logs
|
||||||
|
|||||||
31
client/public/components/object.tsx
Normal file
31
client/public/components/object.tsx
Normal file
@ -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<Props> = ({ objectId }) => {
|
||||||
|
const [transactions, setTransactions] = useState([])
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
rek(`/api/objects/${objectId}`).then(setTransactions)
|
||||||
|
}, [objectId])
|
||||||
|
|
||||||
|
return (
|
||||||
|
<table>
|
||||||
|
<tbody>
|
||||||
|
{transactions.map((transaction) => (
|
||||||
|
<tr>
|
||||||
|
<td>{transaction.transactionDate.slice(0, 10)}</td>
|
||||||
|
<td>{transaction.accountNumber}</td>
|
||||||
|
<td>{transaction.amount}</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Result
|
||||||
41
client/public/components/objects_page.tsx
Normal file
41
client/public/components/objects_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 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 (
|
||||||
|
<section>
|
||||||
|
<Head>
|
||||||
|
<title> : Objects</title>
|
||||||
|
</Head>
|
||||||
|
|
||||||
|
<h1>Objects</h1>
|
||||||
|
<div className={s.objects}>
|
||||||
|
{objects.map((object) => (
|
||||||
|
<button onClick={() => setCurrentObject(object)}>
|
||||||
|
{object.dimensionName}: {object.name}
|
||||||
|
</button>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{currentObject ? (
|
||||||
|
<div>
|
||||||
|
<h2>{currentObject}</h2>
|
||||||
|
<Object objectId={currentObject.id} />
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
</section>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default ObjectsPage
|
||||||
@ -1,4 +1,5 @@
|
|||||||
import Start from './components/start_page.tsx'
|
import Start from './components/start_page.tsx'
|
||||||
|
import Objects from './components/objects_page.tsx'
|
||||||
import Results from './components/results_page.tsx'
|
import Results from './components/results_page.tsx'
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
@ -8,6 +9,12 @@ export default [
|
|||||||
title: 'Start',
|
title: 'Start',
|
||||||
component: Start,
|
component: Start,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
path: '/objects',
|
||||||
|
name: 'objects',
|
||||||
|
title: 'Objects',
|
||||||
|
component: Objects,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/results',
|
path: '/results',
|
||||||
name: 'results',
|
name: 'results',
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'
|
import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'
|
||||||
import knex from '../lib/knex.ts'
|
import knex from '../lib/knex.ts'
|
||||||
|
import StatusError from '../lib/status_error.ts'
|
||||||
|
|
||||||
export const FinancialYear = Type.Object({
|
export const FinancialYear = Type.Object({
|
||||||
year: Type.Number(),
|
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({
|
fastify.route({
|
||||||
url: '/results',
|
url: '/results',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user