types and linting

This commit is contained in:
Linus Miller 2025-12-09 01:05:20 +01:00
parent ae23e9fbd1
commit 504b47335d
27 changed files with 63 additions and 57 deletions

View File

@ -11,7 +11,7 @@ get {
} }
params:path { params:path {
id: id: 200
} }
settings { settings {

5
.oxlintrc.json Normal file
View File

@ -0,0 +1,5 @@
{
"rules": {
"no-console": [2, { "allow": ["error", "info"] }]
}
}

View File

@ -2,7 +2,6 @@ import fs from 'node:fs/promises'
import { existsSync } from 'node:fs' import { existsSync } from 'node:fs'
import path from 'node:path' import path from 'node:path'
import knex from '../server/lib/knex.ts' import knex from '../server/lib/knex.ts'
import split from '../server/lib/split.ts'
import { csvParseRows } from 'd3-dsv' import { csvParseRows } from 'd3-dsv'
const csvFilename = process.argv[2] const csvFilename = process.argv[2]
@ -14,18 +13,18 @@ const trx = await knex.transaction()
for (const row of rows.toReversed()) { for (const row of rows.toReversed()) {
const [ const [
phmNumber, phmNumber,
type, // type,
supplierId, // supplierId,
supplierName, supplierName,
invoiceDate, invoiceDate,
dueDate, dueDate,
invoiceNumber, invoiceNumber,
ocr, ocr,
amount, amount,
vat, // vat,
balance, // balance,
currency, // currency,
status, // status,
filesString, filesString,
] = row ] = row

View File

@ -5,7 +5,7 @@ import knex from '../server/lib/knex.ts'
for await (const file of process.argv.slice(2)) { for await (const file of process.argv.slice(2)) {
const fh = await fs.open(file) const fh = await fs.open(file)
console.log(`- parsing file: ${file}`) console.info(`- parsing file: ${file}`)
await parseStream(fh.readableWebStream()) await parseStream(fh.readableWebStream())

View File

@ -22,7 +22,7 @@ const remember = throttle(function remember() {
) )
}, 100) }, 100)
export default function App({ error, url, title }) { export default function App({ error, title }) {
useEffect(() => { useEffect(() => {
addEventListener('scroll', remember) addEventListener('scroll', remember)
@ -31,7 +31,6 @@ export default function App({ error, url, title }) {
const onRouteChange = useCallback(() => { const onRouteChange = useCallback(() => {
const offset = get(window.history, 'state.scrollTop') const offset = get(window.history, 'state.scrollTop')
console.log('offset', offset)
setTimeout(() => { setTimeout(() => {
window.scrollTo(0, offset || 0) window.scrollTo(0, offset || 0)

View File

@ -3,8 +3,6 @@ import { useEffect, useState } from 'preact/hooks'
import cn from 'classnames' import cn from 'classnames'
import rek from 'rek' import rek from 'rek'
import Head from './head.ts' import Head from './head.ts'
import Balance from './balance.tsx'
import Balances from './balances.tsx'
import { formatNumber } from '../utils/format_number.ts' import { formatNumber } from '../utils/format_number.ts'
import s from './balances_page.module.scss' import s from './balances_page.module.scss'

View File

@ -1,14 +1,15 @@
import { h } from 'preact' import { h } from 'preact'
import { useEffect, useState } from 'preact/hooks' import { useEffect, useState } from 'preact/hooks'
import { useRoute, useLocation } from 'preact-iso' import { useRoute } from 'preact-iso'
import { formatNumber } from '../utils/format_number.ts' import { formatNumber } from '../utils/format_number.ts'
import rek from 'rek' import rek from 'rek'
import { type Entry } from '../../../shared/types.ts'
import Head from './head.ts' import Head from './head.ts'
const EntriesPage = () => { const EntriesPage = () => {
const [entry, setEntry] = useState([]) const [entry, setEntry] = useState<Entry>(null)
const location = useLocation()
const route = useRoute() const route = useRoute()
useEffect(() => { useEffect(() => {

View File

@ -2,21 +2,13 @@ import { h } from 'preact'
import { useEffect, useState } from 'preact/hooks' import { useEffect, useState } from 'preact/hooks'
import rek from 'rek' import rek from 'rek'
import Head from './head.ts' import Head from './head.ts'
import Invoice from './invoice.tsx'
const InvoicesPage = () => { const InvoicesPage = () => {
const [suppliers, setSuppliers] = useState([]) const [suppliers, setSuppliers] = useState([])
const [financialYears, setFinancialYears] = useState([])
const [currentYear, setCurrentYear] = useState<number>(null)
useEffect(() => { useEffect(() => {
rek('/api/suppliers').then((suppliers) => setSuppliers(suppliers)) rek('/api/suppliers').then((suppliers) => setSuppliers(suppliers))
// rek('/api/financial-years').then((financialYears) => {
// setFinancialYears(financialYears)
// setCurrentYear(financialYears[financialYears.length - 1].year)
// })
}, []) }, [])
console.log(suppliers)
return ( return (
<section> <section>

View File

@ -3,8 +3,6 @@ import { useEffect, useState } from 'preact/hooks'
import cn from 'classnames' import cn from 'classnames'
import rek from 'rek' import rek from 'rek'
import Head from './head.ts' import Head from './head.ts'
import Result from './result.tsx'
import Results from './results.tsx'
import { formatNumber } from '../utils/format_number.ts' import { formatNumber } from '../utils/format_number.ts'
import s from './results_page.module.scss' import s from './results_page.module.scss'

View File

@ -14,8 +14,6 @@ const TransactionsPage = () => {
const location = useLocation() const location = useLocation()
console.log(location)
const onSubmit = useCallback((e: SubmitEvent) => { const onSubmit = useCallback((e: SubmitEvent) => {
e.preventDefault() e.preventDefault()

View File

@ -46,8 +46,6 @@ export default function selectFactory({ styles }): FunctionComponent<{
const [touched, setTouched] = useState(false) const [touched, setTouched] = useState(false)
const selectRef = useRef<HTMLSelectElement>() const selectRef = useRef<HTMLSelectElement>()
console.log(options)
const onBlur = useCallback(() => setTouched(true), []) const onBlur = useCallback(() => setTouched(true), [])
useEffect(() => { useEffect(() => {

View File

@ -326,7 +326,6 @@ export default async function parseStream(stream: ReadableStream, decoder: Decod
}) })
.returning(['id', 'description']) .returning(['id', 'description'])
)[0] )[0]
console.log(currentEntry)
break break
} }
@ -337,6 +336,7 @@ export default async function parseStream(stream: ReadableStream, decoder: Decod
await trx.commit() await trx.commit()
// oxlint-disable-next-line no-console
console.dir(details) console.dir(details)
console.info(`DONE!: ${currentYear.startDate} - ${currentYear.endDate}`) console.info(`DONE!: ${currentYear.startDate} - ${currentYear.endDate}`)

View File

@ -109,12 +109,10 @@ async function setupEntry(fastify: FastifyInstance, entry: Entry, config: Parsed
function createRenderer(fastify, entry, render, manifest) { function createRenderer(fastify, entry, render, manifest) {
const files = manifest[`${entry.name}/client.ts`] const files = manifest[`${entry.name}/client.ts`]
console.log(files)
const bundle = path.join('/', files.file) const bundle = path.join('/', files.file)
const preload = files.imports?.map((name) => path.join('/', manifest[name].file)) const preload = files.imports?.map((name) => path.join('/', manifest[name].file))
const css = files.css?.map((name) => path.join('/', name)) const css = files.css?.map((name) => path.join('/', name))
console.log(css)
return (url, ctx) => { return (url, ctx) => {
ctx = Object.assign({ url }, entry.ctx, ctx) ctx = Object.assign({ url }, entry.ctx, ctx)

View File

@ -1,6 +1,5 @@
import _ from 'lodash' import _ from 'lodash'
import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'
import knex from '../lib/knex.ts'
import accounts from './api/accounts.ts' import accounts from './api/accounts.ts'
import balances from './api/balances.ts' import balances from './api/balances.ts'
@ -13,14 +12,6 @@ import results from './api/results.ts'
import suppliers from './api/suppliers.ts' import suppliers from './api/suppliers.ts'
import transactions from './api/transactions.ts' import transactions from './api/transactions.ts'
export const FinancialYear = Type.Object({
year: Type.Number(),
startDate: Type.String(),
endDate: Type.String(),
})
export type FinancialYearType = Static<typeof FinancialYear>
const apiRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { const apiRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
fastify.register(accounts, { prefix: '/accounts' }) fastify.register(accounts, { prefix: '/accounts' })
fastify.register(balances, { prefix: '/balances' }) fastify.register(balances, { prefix: '/balances' })

View File

@ -1,5 +1,5 @@
import _ from 'lodash' import _ from 'lodash'
import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'
import knex from '../../lib/knex.ts' import knex from '../../lib/knex.ts'
const accountRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { const accountRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {

View File

@ -1,5 +1,5 @@
import _ from 'lodash' import _ from 'lodash'
import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'
import knex from '../../lib/knex.ts' import knex from '../../lib/knex.ts'
const balanceRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { const balanceRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {

View File

@ -1,5 +1,5 @@
import _ from 'lodash' import _ from 'lodash'
import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' import { Type, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'
import knex from '../../lib/knex.ts' import knex from '../../lib/knex.ts'
const entryRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { const entryRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
@ -44,7 +44,12 @@ const entryRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
.first('e.id', 'j.identifier AS journal', 'e.number', 'e.entryDate', 'e.transactionDate', 'e.description', { .first('e.id', 'j.identifier AS journal', 'e.number', 'e.entryDate', 'e.transactionDate', 'e.description', {
transactions: knex transactions: knex
.select(knex.raw('json_agg(transactions)')) .select(knex.raw('json_agg(transactions)'))
.from(knex('transaction').select('*').where('transaction.entryId', knex.ref('e.id')).as('transactions')), .from(
knex('transaction')
.select('account_number AS accountNumber', 'object_id AS objectId')
.where('transaction.entryId', knex.ref('e.id'))
.as('transactions'),
),
}) })
.sum('t.amount AS amount') .sum('t.amount AS amount')
.innerJoin('journal AS j', 'e.journalId', 'j.id') .innerJoin('journal AS j', 'e.journalId', 'j.id')

View File

@ -1,5 +1,5 @@
import _ from 'lodash' import _ from 'lodash'
import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'
import knex from '../../lib/knex.ts' import knex from '../../lib/knex.ts'
const financialYearRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { const financialYearRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {

View File

@ -1,5 +1,5 @@
import _ from 'lodash' import _ from 'lodash'
import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'
import knex from '../../lib/knex.ts' import knex from '../../lib/knex.ts'
const journalRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { const journalRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {

View File

@ -1,5 +1,5 @@
import _ from 'lodash' import _ from 'lodash'
import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' import { Type, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'
import knex from '../../lib/knex.ts' import knex from '../../lib/knex.ts'
const objectRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { const objectRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {

View File

@ -1,5 +1,5 @@
import _ from 'lodash' import _ from 'lodash'
import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' import { Type, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'
import knex from '../../lib/knex.ts' import knex from '../../lib/knex.ts'
const resultRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { const resultRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {

View File

@ -1,12 +1,12 @@
import _ from 'lodash' import _ from 'lodash'
import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' import { Type, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox'
import knex from '../../lib/knex.ts' import knex from '../../lib/knex.ts'
const journalRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { const journalRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
fastify.route({ fastify.route({
url: '/', url: '/',
method: 'GET', method: 'GET',
async handler(req) { async handler() {
return knex('supplier').select('*').orderBy('name') return knex('supplier').select('*').orderBy('name')
}, },
}) })
@ -33,8 +33,6 @@ const journalRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
}), }),
}, },
async handler(req) { async handler(req) {
console.dir(req.body)
const suppliers = await knex('supplier').select('*').whereIn('id', req.body.ids) const suppliers = await knex('supplier').select('*').whereIn('id', req.body.ids)
const trx = await knex.transaction() const trx = await knex.transaction()

View File

@ -1,5 +1,5 @@
import _ from 'lodash' import _ from 'lodash'
import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' import { Type, 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' import StatusError from '../../lib/status_error.ts'

View File

26
shared/types.ts Normal file
View File

@ -0,0 +1,26 @@
// export const FinancialYear = Type.Object({
// year: Type.Number(),
// startDate: Type.String(),
// endDate: Type.String(),
// })
// export type FinancialYearType = Static<typeof FinancialYear>
export interface Transaction {
description: string
amount: number
}
export interface Entry {
id: number
journal: string
number: number
amount: number
description: string
transactionDate: string
entryDate: string
transactions: {
account_number: number
description: string
amount: number
}[]
}

View File

@ -12,5 +12,5 @@
"erasableSyntaxOnly": true, "erasableSyntaxOnly": true,
"allowArbitraryExtensions": true "allowArbitraryExtensions": true
}, },
"include": ["global.d.ts", "bin", "client", "server"] "include": ["bin", "client", "server", "shared"]
} }