From 504b47335d8e37a8c64fd579271db4098759c736 Mon Sep 17 00:00:00 2001 From: Linus Miller Date: Tue, 9 Dec 2025 01:05:20 +0100 Subject: [PATCH] types and linting --- .bruno/BRF/api-entries--id.bru | 2 +- .oxlintrc.json | 5 ++++ bin/add_phm_invoices.ts | 13 +++++----- bin/parse_file.ts | 2 +- client/public/components/app.tsx | 3 +-- client/public/components/balances_page.tsx | 2 -- client/public/components/entry_page.tsx | 7 ++--- client/public/components/invoices.tsx | 0 client/public/components/invoices_page.tsx | 8 ------ client/public/components/results_page.tsx | 2 -- .../public/components/transactions_page.tsx | 2 -- client/shared/components/select_factory.tsx | 2 -- server/lib/parse_stream.ts | 2 +- server/plugins/vite/production.ts | 2 -- server/routes/api.ts | 11 +------- server/routes/api/accounts.ts | 2 +- server/routes/api/balances.ts | 2 +- server/routes/api/entries.ts | 9 +++++-- server/routes/api/financial_years.ts | 2 +- server/routes/api/journals.ts | 2 +- server/routes/api/objects.ts | 2 +- server/routes/api/results.ts | 2 +- server/routes/api/suppliers.ts | 6 ++--- server/routes/api/transactions.ts | 2 +- global.d.ts => shared/global.d.ts | 0 shared/types.ts | 26 +++++++++++++++++++ tsconfig.json | 2 +- 27 files changed, 63 insertions(+), 57 deletions(-) create mode 100644 .oxlintrc.json delete mode 100644 client/public/components/invoices.tsx rename global.d.ts => shared/global.d.ts (100%) create mode 100644 shared/types.ts diff --git a/.bruno/BRF/api-entries--id.bru b/.bruno/BRF/api-entries--id.bru index 89aa559..15c4da3 100644 --- a/.bruno/BRF/api-entries--id.bru +++ b/.bruno/BRF/api-entries--id.bru @@ -11,7 +11,7 @@ get { } params:path { - id: + id: 200 } settings { diff --git a/.oxlintrc.json b/.oxlintrc.json new file mode 100644 index 0000000..4419657 --- /dev/null +++ b/.oxlintrc.json @@ -0,0 +1,5 @@ +{ + "rules": { + "no-console": [2, { "allow": ["error", "info"] }] + } +} diff --git a/bin/add_phm_invoices.ts b/bin/add_phm_invoices.ts index 67f0691..80990b6 100644 --- a/bin/add_phm_invoices.ts +++ b/bin/add_phm_invoices.ts @@ -2,7 +2,6 @@ import fs from 'node:fs/promises' import { existsSync } from 'node:fs' import path from 'node:path' import knex from '../server/lib/knex.ts' -import split from '../server/lib/split.ts' import { csvParseRows } from 'd3-dsv' const csvFilename = process.argv[2] @@ -14,18 +13,18 @@ const trx = await knex.transaction() for (const row of rows.toReversed()) { const [ phmNumber, - type, - supplierId, + // type, + // supplierId, supplierName, invoiceDate, dueDate, invoiceNumber, ocr, amount, - vat, - balance, - currency, - status, + // vat, + // balance, + // currency, + // status, filesString, ] = row diff --git a/bin/parse_file.ts b/bin/parse_file.ts index 8a03db6..a5b48a1 100644 --- a/bin/parse_file.ts +++ b/bin/parse_file.ts @@ -5,7 +5,7 @@ import knex from '../server/lib/knex.ts' for await (const file of process.argv.slice(2)) { const fh = await fs.open(file) - console.log(`- parsing file: ${file}`) + console.info(`- parsing file: ${file}`) await parseStream(fh.readableWebStream()) diff --git a/client/public/components/app.tsx b/client/public/components/app.tsx index 3b0b139..0045c47 100644 --- a/client/public/components/app.tsx +++ b/client/public/components/app.tsx @@ -22,7 +22,7 @@ const remember = throttle(function remember() { ) }, 100) -export default function App({ error, url, title }) { +export default function App({ error, title }) { useEffect(() => { addEventListener('scroll', remember) @@ -31,7 +31,6 @@ export default function App({ error, url, title }) { const onRouteChange = useCallback(() => { const offset = get(window.history, 'state.scrollTop') - console.log('offset', offset) setTimeout(() => { window.scrollTo(0, offset || 0) diff --git a/client/public/components/balances_page.tsx b/client/public/components/balances_page.tsx index dfe38c5..3c956a9 100644 --- a/client/public/components/balances_page.tsx +++ b/client/public/components/balances_page.tsx @@ -3,8 +3,6 @@ import { useEffect, useState } from 'preact/hooks' import cn from 'classnames' import rek from 'rek' import Head from './head.ts' -import Balance from './balance.tsx' -import Balances from './balances.tsx' import { formatNumber } from '../utils/format_number.ts' import s from './balances_page.module.scss' diff --git a/client/public/components/entry_page.tsx b/client/public/components/entry_page.tsx index 4283a87..4b0b2ac 100644 --- a/client/public/components/entry_page.tsx +++ b/client/public/components/entry_page.tsx @@ -1,14 +1,15 @@ import { h } from 'preact' 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 rek from 'rek' +import { type Entry } from '../../../shared/types.ts' + import Head from './head.ts' const EntriesPage = () => { - const [entry, setEntry] = useState([]) - const location = useLocation() + const [entry, setEntry] = useState(null) const route = useRoute() useEffect(() => { diff --git a/client/public/components/invoices.tsx b/client/public/components/invoices.tsx deleted file mode 100644 index e69de29..0000000 diff --git a/client/public/components/invoices_page.tsx b/client/public/components/invoices_page.tsx index 4f26071..de7341f 100644 --- a/client/public/components/invoices_page.tsx +++ b/client/public/components/invoices_page.tsx @@ -2,21 +2,13 @@ import { h } from 'preact' import { useEffect, useState } from 'preact/hooks' import rek from 'rek' import Head from './head.ts' -import Invoice from './invoice.tsx' const InvoicesPage = () => { const [suppliers, setSuppliers] = useState([]) - const [financialYears, setFinancialYears] = useState([]) - const [currentYear, setCurrentYear] = useState(null) useEffect(() => { 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 (
diff --git a/client/public/components/results_page.tsx b/client/public/components/results_page.tsx index 29a63cc..fa092d2 100644 --- a/client/public/components/results_page.tsx +++ b/client/public/components/results_page.tsx @@ -3,8 +3,6 @@ import { useEffect, useState } from 'preact/hooks' import cn from 'classnames' import rek from 'rek' import Head from './head.ts' -import Result from './result.tsx' -import Results from './results.tsx' import { formatNumber } from '../utils/format_number.ts' import s from './results_page.module.scss' diff --git a/client/public/components/transactions_page.tsx b/client/public/components/transactions_page.tsx index 1a9141f..8a6a5f7 100644 --- a/client/public/components/transactions_page.tsx +++ b/client/public/components/transactions_page.tsx @@ -14,8 +14,6 @@ const TransactionsPage = () => { const location = useLocation() - console.log(location) - const onSubmit = useCallback((e: SubmitEvent) => { e.preventDefault() diff --git a/client/shared/components/select_factory.tsx b/client/shared/components/select_factory.tsx index cff22cc..a03996b 100644 --- a/client/shared/components/select_factory.tsx +++ b/client/shared/components/select_factory.tsx @@ -46,8 +46,6 @@ export default function selectFactory({ styles }): FunctionComponent<{ const [touched, setTouched] = useState(false) const selectRef = useRef() - console.log(options) - const onBlur = useCallback(() => setTouched(true), []) useEffect(() => { diff --git a/server/lib/parse_stream.ts b/server/lib/parse_stream.ts index 8317d6f..df85492 100644 --- a/server/lib/parse_stream.ts +++ b/server/lib/parse_stream.ts @@ -326,7 +326,6 @@ export default async function parseStream(stream: ReadableStream, decoder: Decod }) .returning(['id', 'description']) )[0] - console.log(currentEntry) break } @@ -337,6 +336,7 @@ export default async function parseStream(stream: ReadableStream, decoder: Decod await trx.commit() + // oxlint-disable-next-line no-console console.dir(details) console.info(`DONE!: ${currentYear.startDate} - ${currentYear.endDate}`) diff --git a/server/plugins/vite/production.ts b/server/plugins/vite/production.ts index e98aca3..b44d62d 100644 --- a/server/plugins/vite/production.ts +++ b/server/plugins/vite/production.ts @@ -109,12 +109,10 @@ async function setupEntry(fastify: FastifyInstance, entry: Entry, config: Parsed function createRenderer(fastify, entry, render, manifest) { const files = manifest[`${entry.name}/client.ts`] - console.log(files) const bundle = path.join('/', files.file) const preload = files.imports?.map((name) => path.join('/', manifest[name].file)) const css = files.css?.map((name) => path.join('/', name)) - console.log(css) return (url, ctx) => { ctx = Object.assign({ url }, entry.ctx, ctx) diff --git a/server/routes/api.ts b/server/routes/api.ts index e96c999..3ef5211 100644 --- a/server/routes/api.ts +++ b/server/routes/api.ts @@ -1,6 +1,5 @@ import _ from 'lodash' -import { Type, type Static, type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' -import knex from '../lib/knex.ts' +import { type FastifyPluginCallbackTypebox } from '@fastify/type-provider-typebox' import accounts from './api/accounts.ts' import balances from './api/balances.ts' @@ -13,14 +12,6 @@ import results from './api/results.ts' import suppliers from './api/suppliers.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 - const apiRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { fastify.register(accounts, { prefix: '/accounts' }) fastify.register(balances, { prefix: '/balances' }) diff --git a/server/routes/api/accounts.ts b/server/routes/api/accounts.ts index 584234a..406be01 100644 --- a/server/routes/api/accounts.ts +++ b/server/routes/api/accounts.ts @@ -1,5 +1,5 @@ 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' const accountRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { diff --git a/server/routes/api/balances.ts b/server/routes/api/balances.ts index ee20c32..1ed5497 100644 --- a/server/routes/api/balances.ts +++ b/server/routes/api/balances.ts @@ -1,5 +1,5 @@ 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' const balanceRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { diff --git a/server/routes/api/entries.ts b/server/routes/api/entries.ts index 84a895e..3940b76 100644 --- a/server/routes/api/entries.ts +++ b/server/routes/api/entries.ts @@ -1,5 +1,5 @@ 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' 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', { transactions: knex .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') .innerJoin('journal AS j', 'e.journalId', 'j.id') diff --git a/server/routes/api/financial_years.ts b/server/routes/api/financial_years.ts index 2540767..ba8496a 100644 --- a/server/routes/api/financial_years.ts +++ b/server/routes/api/financial_years.ts @@ -1,5 +1,5 @@ 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' const financialYearRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { diff --git a/server/routes/api/journals.ts b/server/routes/api/journals.ts index 365e269..bf333dc 100644 --- a/server/routes/api/journals.ts +++ b/server/routes/api/journals.ts @@ -1,5 +1,5 @@ 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' const journalRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { diff --git a/server/routes/api/objects.ts b/server/routes/api/objects.ts index cc67dd3..7f69eb2 100644 --- a/server/routes/api/objects.ts +++ b/server/routes/api/objects.ts @@ -1,5 +1,5 @@ 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' const objectRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { diff --git a/server/routes/api/results.ts b/server/routes/api/results.ts index 49f61ed..99edb68 100644 --- a/server/routes/api/results.ts +++ b/server/routes/api/results.ts @@ -1,5 +1,5 @@ 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' const resultRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { diff --git a/server/routes/api/suppliers.ts b/server/routes/api/suppliers.ts index fa9f1fa..65e413c 100644 --- a/server/routes/api/suppliers.ts +++ b/server/routes/api/suppliers.ts @@ -1,12 +1,12 @@ 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' const journalRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { fastify.route({ url: '/', method: 'GET', - async handler(req) { + async handler() { return knex('supplier').select('*').orderBy('name') }, }) @@ -33,8 +33,6 @@ const journalRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => { }), }, async handler(req) { - console.dir(req.body) - const suppliers = await knex('supplier').select('*').whereIn('id', req.body.ids) const trx = await knex.transaction() diff --git a/server/routes/api/transactions.ts b/server/routes/api/transactions.ts index 929fd9b..461d304 100644 --- a/server/routes/api/transactions.ts +++ b/server/routes/api/transactions.ts @@ -1,5 +1,5 @@ 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 StatusError from '../../lib/status_error.ts' diff --git a/global.d.ts b/shared/global.d.ts similarity index 100% rename from global.d.ts rename to shared/global.d.ts diff --git a/shared/types.ts b/shared/types.ts new file mode 100644 index 0000000..067481f --- /dev/null +++ b/shared/types.ts @@ -0,0 +1,26 @@ +// export const FinancialYear = Type.Object({ +// year: Type.Number(), +// startDate: Type.String(), +// endDate: Type.String(), +// }) + +// export type FinancialYearType = Static +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 + }[] +} diff --git a/tsconfig.json b/tsconfig.json index 31744a7..d0ae0d4 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -12,5 +12,5 @@ "erasableSyntaxOnly": true, "allowArbitraryExtensions": true }, - "include": ["global.d.ts", "bin", "client", "server"] + "include": ["bin", "client", "server", "shared"] }