types and linting
This commit is contained in:
parent
ae23e9fbd1
commit
504b47335d
@ -11,7 +11,7 @@ get {
|
||||
}
|
||||
|
||||
params:path {
|
||||
id:
|
||||
id: 200
|
||||
}
|
||||
|
||||
settings {
|
||||
|
||||
5
.oxlintrc.json
Normal file
5
.oxlintrc.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"rules": {
|
||||
"no-console": [2, { "allow": ["error", "info"] }]
|
||||
}
|
||||
}
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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())
|
||||
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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'
|
||||
|
||||
|
||||
@ -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<Entry>(null)
|
||||
const route = useRoute()
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@ -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<number>(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 (
|
||||
<section>
|
||||
|
||||
@ -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'
|
||||
|
||||
|
||||
@ -14,8 +14,6 @@ const TransactionsPage = () => {
|
||||
|
||||
const location = useLocation()
|
||||
|
||||
console.log(location)
|
||||
|
||||
const onSubmit = useCallback((e: SubmitEvent) => {
|
||||
e.preventDefault()
|
||||
|
||||
|
||||
@ -46,8 +46,6 @@ export default function selectFactory({ styles }): FunctionComponent<{
|
||||
const [touched, setTouched] = useState(false)
|
||||
const selectRef = useRef<HTMLSelectElement>()
|
||||
|
||||
console.log(options)
|
||||
|
||||
const onBlur = useCallback(() => setTouched(true), [])
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@ -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}`)
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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<typeof FinancialYear>
|
||||
|
||||
const apiRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
|
||||
fastify.register(accounts, { prefix: '/accounts' })
|
||||
fastify.register(balances, { prefix: '/balances' })
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -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')
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -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) => {
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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'
|
||||
|
||||
|
||||
0
global.d.ts → shared/global.d.ts
vendored
0
global.d.ts → shared/global.d.ts
vendored
26
shared/types.ts
Normal file
26
shared/types.ts
Normal 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
|
||||
}[]
|
||||
}
|
||||
@ -12,5 +12,5 @@
|
||||
"erasableSyntaxOnly": true,
|
||||
"allowArbitraryExtensions": true
|
||||
},
|
||||
"include": ["global.d.ts", "bin", "client", "server"]
|
||||
"include": ["bin", "client", "server", "shared"]
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user