convert postgres database to camelCase

This commit is contained in:
Linus Miller 2025-12-14 15:55:49 +01:00
parent 3b203a9112
commit 1ff4684ed3
11 changed files with 142 additions and 159 deletions

View File

@ -62,7 +62,7 @@ const EntryPage: FunctionComponent = () => {
<tbody>
{entry?.transactions?.map((transaction) => (
<tr>
<td>{transaction.account_number}</td>
<td>{transaction.accountNumber}</td>
<td className='tar'>{transaction.amount >= 0 ? formatNumber(transaction.amount) : null}</td>
<td className='tar'>{transaction.amount < 0 ? formatNumber(Math.abs(transaction.amount)) : null}</td>
<td>{transaction.description}</td>

View File

@ -86,9 +86,9 @@ const InvoicePage: FunctionComponent = () => {
{invoice?.transactions?.map((transaction) => (
<tr>
<td>
<a href={`/entries/${transaction.entry_id}`}>{transaction.entry_id}</a>
<a href={`/entries/${transaction.entryId}`}>{transaction.entryId}</a>
</td>
<td>{transaction.account_number}</td>
<td>{transaction.accountNumber}</td>
<td>{transaction.amount >= 0 ? formatNumber(transaction.amount) : null}</td>
<td>{transaction.amount < 0 ? formatNumber(Math.abs(transaction.amount)) : null}</td>
<td>{transaction.description}</td>

View File

@ -49,23 +49,23 @@ SET default_table_access_method = heap;
CREATE TABLE public.account (
id integer NOT NULL,
number smallint NOT NULL,
financial_year_id integer NOT NULL,
"financialYearId" integer NOT NULL,
description text NOT NULL,
sru smallint
);
--
-- Name: account_balance; Type: TABLE; Schema: public; Owner: -
-- Name: accountBalance; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.account_balance (
account_number integer NOT NULL,
financial_year_id integer NOT NULL,
CREATE TABLE public."accountBalance" (
"accountNumber" integer NOT NULL,
"financialYearId" integer NOT NULL,
"in" numeric(12,2) DEFAULT 0 NOT NULL,
"out" numeric(12,2) DEFAULT 0 NOT NULL,
in_quantity integer,
out_quantity integer
"inQuantity" integer,
"outQuantity" integer
);
@ -90,21 +90,21 @@ ALTER SEQUENCE public.account_id_seq OWNED BY public.account.id;
--
-- Name: aliases_to_supplier; Type: TABLE; Schema: public; Owner: -
-- Name: aliasesToSupplier; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.aliases_to_supplier (
CREATE TABLE public."aliasesToSupplier" (
id integer NOT NULL,
supplier_id integer NOT NULL,
"supplierId" integer NOT NULL,
alias text NOT NULL
);
--
-- Name: aliases_to_supplier_id_seq; Type: SEQUENCE; Schema: public; Owner: -
-- Name: aliasesToSupplier_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.aliases_to_supplier_id_seq
CREATE SEQUENCE public."aliasesToSupplier_id_seq"
AS integer
START WITH 1
INCREMENT BY 1
@ -114,10 +114,10 @@ CREATE SEQUENCE public.aliases_to_supplier_id_seq
--
-- Name: aliases_to_supplier_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
-- Name: aliasesToSupplier_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.aliases_to_supplier_id_seq OWNED BY public.aliases_to_supplier.id;
ALTER SEQUENCE public."aliasesToSupplier_id_seq" OWNED BY public."aliasesToSupplier".id;
--
@ -157,12 +157,12 @@ ALTER SEQUENCE public.dimension_id_seq OWNED BY public.dimension.id;
CREATE TABLE public.entry (
id integer NOT NULL,
financial_year_id integer NOT NULL,
journal_id integer NOT NULL,
"financialYearId" integer NOT NULL,
"journalId" integer NOT NULL,
number integer NOT NULL,
transaction_date date NOT NULL,
"transactionDate" date NOT NULL,
description text,
entry_date date NOT NULL,
"entryDate" date NOT NULL,
signature text
);
@ -218,32 +218,32 @@ ALTER SEQUENCE public.file_id_seq OWNED BY public.file.id;
--
-- Name: files_to_invoice; Type: TABLE; Schema: public; Owner: -
-- Name: filesToInvoice; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.files_to_invoice (
invoice_id integer NOT NULL,
file_id integer NOT NULL
CREATE TABLE public."filesToInvoice" (
"invoiceId" integer NOT NULL,
"fileId" integer NOT NULL
);
--
-- Name: financial_year; Type: TABLE; Schema: public; Owner: -
-- Name: financialYear; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.financial_year (
CREATE TABLE public."financialYear" (
id integer NOT NULL,
year integer NOT NULL,
start_date date NOT NULL,
end_date date NOT NULL
"startDate" date NOT NULL,
"endDate" date NOT NULL
);
--
-- Name: financial_year_id_seq; Type: SEQUENCE; Schema: public; Owner: -
-- Name: financialYear_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.financial_year_id_seq
CREATE SEQUENCE public."financialYear_id_seq"
AS integer
START WITH 1
INCREMENT BY 1
@ -253,10 +253,10 @@ CREATE SEQUENCE public.financial_year_id_seq
--
-- Name: financial_year_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
-- Name: financialYear_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.financial_year_id_seq OWNED BY public.financial_year.id;
ALTER SEQUENCE public."financialYear_id_seq" OWNED BY public."financialYear".id;
--
@ -265,13 +265,13 @@ ALTER SEQUENCE public.financial_year_id_seq OWNED BY public.financial_year.id;
CREATE TABLE public.invoice (
id integer NOT NULL,
financial_year_id integer,
supplier_id integer NOT NULL,
fisken_number integer,
phm_number integer,
invoice_number text,
invoice_date date,
due_date date,
"financialYearId" integer,
"supplierId" integer NOT NULL,
"fiskenNumber" integer,
"phmNumber" integer,
"invoiceNumber" text,
"invoiceDate" date,
"dueDate" date,
ocr text,
amount numeric(12,2)
);
@ -334,7 +334,7 @@ ALTER SEQUENCE public.journal_id_seq OWNED BY public.journal.id;
CREATE TABLE public.object (
id integer NOT NULL,
dimension_id integer NOT NULL,
"dimensionId" integer NOT NULL,
number smallint NOT NULL,
name text
);
@ -367,8 +367,8 @@ ALTER SEQUENCE public.object_id_seq OWNED BY public.object.id;
CREATE TABLE public.supplier (
id integer NOT NULL,
name text,
supplier_type_id integer NOT NULL,
tax_id text
"supplierTypeId" integer NOT NULL,
"taxId" text
);
@ -393,20 +393,20 @@ ALTER SEQUENCE public.supplier_id_seq OWNED BY public.supplier.id;
--
-- Name: supplier_type; Type: TABLE; Schema: public; Owner: -
-- Name: supplierType; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.supplier_type (
CREATE TABLE public."supplierType" (
id integer NOT NULL,
name text NOT NULL
);
--
-- Name: supplier_type_id_seq; Type: SEQUENCE; Schema: public; Owner: -
-- Name: supplierType_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.supplier_type_id_seq
CREATE SEQUENCE public."supplierType_id_seq"
AS integer
START WITH 1
INCREMENT BY 1
@ -416,10 +416,10 @@ CREATE SEQUENCE public.supplier_type_id_seq
--
-- Name: supplier_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
-- Name: supplierType_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.supplier_type_id_seq OWNED BY public.supplier_type.id;
ALTER SEQUENCE public."supplierType_id_seq" OWNED BY public."supplierType".id;
--
@ -428,15 +428,15 @@ ALTER SEQUENCE public.supplier_type_id_seq OWNED BY public.supplier_type.id;
CREATE TABLE public.transaction (
id integer NOT NULL,
entry_id integer NOT NULL,
account_number smallint NOT NULL,
"entryId" integer NOT NULL,
"accountNumber" smallint NOT NULL,
amount numeric(12,2) NOT NULL,
object_id integer,
"objectId" integer,
description text,
transaction_date date,
"transactionDate" date,
quantity numeric(12,2),
signature text,
invoice_id integer
"invoiceId" integer
);
@ -461,12 +461,12 @@ ALTER SEQUENCE public.transaction_id_seq OWNED BY public.transaction.id;
--
-- Name: transactions_to_objects; Type: TABLE; Schema: public; Owner: -
-- Name: transactionsToObjects; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.transactions_to_objects (
transaction_id integer NOT NULL,
object_id integer NOT NULL
CREATE TABLE public."transactionsToObjects" (
"transactionId" integer NOT NULL,
"objectId" integer NOT NULL
);
@ -478,10 +478,10 @@ ALTER TABLE ONLY public.account ALTER COLUMN id SET DEFAULT nextval('public.acco
--
-- Name: aliases_to_supplier id; Type: DEFAULT; Schema: public; Owner: -
-- Name: aliasesToSupplier id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.aliases_to_supplier ALTER COLUMN id SET DEFAULT nextval('public.aliases_to_supplier_id_seq'::regclass);
ALTER TABLE ONLY public."aliasesToSupplier" ALTER COLUMN id SET DEFAULT nextval('public."aliasesToSupplier_id_seq"'::regclass);
--
@ -506,10 +506,10 @@ ALTER TABLE ONLY public.file ALTER COLUMN id SET DEFAULT nextval('public.file_id
--
-- Name: financial_year id; Type: DEFAULT; Schema: public; Owner: -
-- Name: financialYear id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.financial_year ALTER COLUMN id SET DEFAULT nextval('public.financial_year_id_seq'::regclass);
ALTER TABLE ONLY public."financialYear" ALTER COLUMN id SET DEFAULT nextval('public."financialYear_id_seq"'::regclass);
--
@ -541,10 +541,10 @@ ALTER TABLE ONLY public.supplier ALTER COLUMN id SET DEFAULT nextval('public.sup
--
-- Name: supplier_type id; Type: DEFAULT; Schema: public; Owner: -
-- Name: supplierType id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.supplier_type ALTER COLUMN id SET DEFAULT nextval('public.supplier_type_id_seq'::regclass);
ALTER TABLE ONLY public."supplierType" ALTER COLUMN id SET DEFAULT nextval('public."supplierType_id_seq"'::regclass);
--
@ -555,19 +555,19 @@ ALTER TABLE ONLY public.transaction ALTER COLUMN id SET DEFAULT nextval('public.
--
-- Name: account_balance account_balance_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- Name: accountBalance accountBalance_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.account_balance
ADD CONSTRAINT account_balance_pkey PRIMARY KEY (account_number, financial_year_id);
ALTER TABLE ONLY public."accountBalance"
ADD CONSTRAINT "accountBalance_pkey" PRIMARY KEY ("accountNumber", "financialYearId");
--
-- Name: account account_number_financial_year_id_key; Type: CONSTRAINT; Schema: public; Owner: -
-- Name: account account_number_financialYearId_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.account
ADD CONSTRAINT account_number_financial_year_id_key UNIQUE (number, financial_year_id);
ADD CONSTRAINT "account_number_financialYearId_key" UNIQUE (number, "financialYearId");
--
@ -579,19 +579,19 @@ ALTER TABLE ONLY public.account
--
-- Name: aliases_to_supplier aliases_to_supplier_alias_key; Type: CONSTRAINT; Schema: public; Owner: -
-- Name: aliasesToSupplier aliasesToSupplier_alias_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.aliases_to_supplier
ADD CONSTRAINT aliases_to_supplier_alias_key UNIQUE (alias);
ALTER TABLE ONLY public."aliasesToSupplier"
ADD CONSTRAINT "aliasesToSupplier_alias_key" UNIQUE (alias);
--
-- Name: aliases_to_supplier aliases_to_supplier_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- Name: aliasesToSupplier aliasesToSupplier_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.aliases_to_supplier
ADD CONSTRAINT aliases_to_supplier_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public."aliasesToSupplier"
ADD CONSTRAINT "aliasesToSupplier_pkey" PRIMARY KEY (id);
--
@ -619,35 +619,35 @@ ALTER TABLE ONLY public.file
--
-- Name: files_to_invoice files_to_invoice_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- Name: filesToInvoice filesToInvoice_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.files_to_invoice
ADD CONSTRAINT files_to_invoice_pkey PRIMARY KEY (invoice_id, file_id);
ALTER TABLE ONLY public."filesToInvoice"
ADD CONSTRAINT "filesToInvoice_pkey" PRIMARY KEY ("invoiceId", "fileId");
--
-- Name: financial_year financial_year_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- Name: financialYear financialYear_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.financial_year
ADD CONSTRAINT financial_year_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public."financialYear"
ADD CONSTRAINT "financialYear_pkey" PRIMARY KEY (id);
--
-- Name: financial_year financial_year_start_date_end_date_key; Type: CONSTRAINT; Schema: public; Owner: -
-- Name: financialYear financialYear_startDate_endDate_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.financial_year
ADD CONSTRAINT financial_year_start_date_end_date_key UNIQUE (start_date, end_date);
ALTER TABLE ONLY public."financialYear"
ADD CONSTRAINT "financialYear_startDate_endDate_key" UNIQUE ("startDate", "endDate");
--
-- Name: financial_year financial_year_year_key; Type: CONSTRAINT; Schema: public; Owner: -
-- Name: financialYear financialYear_year_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.financial_year
ADD CONSTRAINT financial_year_year_key UNIQUE (year);
ALTER TABLE ONLY public."financialYear"
ADD CONSTRAINT "financialYear_year_key" UNIQUE (year);
--
@ -667,11 +667,11 @@ ALTER TABLE ONLY public.journal
--
-- Name: object object_dimension_id_number_key; Type: CONSTRAINT; Schema: public; Owner: -
-- Name: object object_dimensionId_number_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.object
ADD CONSTRAINT object_dimension_id_number_key UNIQUE (dimension_id, number);
ADD CONSTRAINT "object_dimensionId_number_key" UNIQUE ("dimensionId", number);
--
@ -691,19 +691,19 @@ ALTER TABLE ONLY public.supplier
--
-- Name: supplier supplier_tax_id_key; Type: CONSTRAINT; Schema: public; Owner: -
-- Name: supplier supplier_taxId_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.supplier
ADD CONSTRAINT supplier_tax_id_key UNIQUE (tax_id);
ADD CONSTRAINT "supplier_taxId_key" UNIQUE ("taxId");
--
-- Name: supplier_type supplier_type_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- Name: supplierType supplierType_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.supplier_type
ADD CONSTRAINT supplier_type_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public."supplierType"
ADD CONSTRAINT "supplierType_pkey" PRIMARY KEY (id);
--
@ -715,107 +715,107 @@ ALTER TABLE ONLY public.transaction
--
-- Name: transactions_to_objects transactions_to_objects_transaction_id_object_id_key; Type: CONSTRAINT; Schema: public; Owner: -
-- Name: transactionsToObjects transactionsToObjects_transactionId_objectId_key; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.transactions_to_objects
ADD CONSTRAINT transactions_to_objects_transaction_id_object_id_key UNIQUE (transaction_id, object_id);
ALTER TABLE ONLY public."transactionsToObjects"
ADD CONSTRAINT "transactionsToObjects_transactionId_objectId_key" UNIQUE ("transactionId", "objectId");
--
-- Name: aliases_to_supplier aliases_to_supplier_supplier_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: aliasesToSupplier aliasesToSupplier_supplierId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.aliases_to_supplier
ADD CONSTRAINT aliases_to_supplier_supplier_id_fkey FOREIGN KEY (supplier_id) REFERENCES public.supplier(id);
ALTER TABLE ONLY public."aliasesToSupplier"
ADD CONSTRAINT "aliasesToSupplier_supplierId_fkey" FOREIGN KEY ("supplierId") REFERENCES public.supplier(id);
--
-- Name: files_to_invoice files_to_invoice_file_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: filesToInvoice filesToInvoice_fileId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.files_to_invoice
ADD CONSTRAINT files_to_invoice_file_id_fkey FOREIGN KEY (file_id) REFERENCES public.file(id);
ALTER TABLE ONLY public."filesToInvoice"
ADD CONSTRAINT "filesToInvoice_fileId_fkey" FOREIGN KEY ("fileId") REFERENCES public.file(id);
--
-- Name: files_to_invoice files_to_invoice_invoice_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: filesToInvoice filesToInvoice_invoiceId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.files_to_invoice
ADD CONSTRAINT files_to_invoice_invoice_id_fkey FOREIGN KEY (invoice_id) REFERENCES public.invoice(id);
ALTER TABLE ONLY public."filesToInvoice"
ADD CONSTRAINT "filesToInvoice_invoiceId_fkey" FOREIGN KEY ("invoiceId") REFERENCES public.invoice(id);
--
-- Name: invoice invoice_financial_year_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: invoice invoice_financialYearId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.invoice
ADD CONSTRAINT invoice_financial_year_id_fkey FOREIGN KEY (financial_year_id) REFERENCES public.financial_year(id);
ADD CONSTRAINT "invoice_financialYearId_fkey" FOREIGN KEY ("financialYearId") REFERENCES public."financialYear"(id);
--
-- Name: invoice invoice_supplier_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: invoice invoice_supplierId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.invoice
ADD CONSTRAINT invoice_supplier_id_fkey FOREIGN KEY (supplier_id) REFERENCES public.supplier(id);
ADD CONSTRAINT "invoice_supplierId_fkey" FOREIGN KEY ("supplierId") REFERENCES public.supplier(id);
--
-- Name: object object_dimension_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: object object_dimensionId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.object
ADD CONSTRAINT object_dimension_id_fkey FOREIGN KEY (dimension_id) REFERENCES public.dimension(id);
ADD CONSTRAINT "object_dimensionId_fkey" FOREIGN KEY ("dimensionId") REFERENCES public.dimension(id);
--
-- Name: supplier supplier_supplier_type_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: supplier supplier_supplierTypeId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.supplier
ADD CONSTRAINT supplier_supplier_type_id_fkey FOREIGN KEY (supplier_type_id) REFERENCES public.supplier_type(id);
ADD CONSTRAINT "supplier_supplierTypeId_fkey" FOREIGN KEY ("supplierTypeId") REFERENCES public."supplierType"(id);
--
-- Name: transaction transaction_entry_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: transaction transaction_entryId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.transaction
ADD CONSTRAINT transaction_entry_id_fkey FOREIGN KEY (entry_id) REFERENCES public.entry(id);
ADD CONSTRAINT "transaction_entryId_fkey" FOREIGN KEY ("entryId") REFERENCES public.entry(id);
--
-- Name: transaction transaction_invoice_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: transaction transaction_invoiceId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.transaction
ADD CONSTRAINT transaction_invoice_id_fkey FOREIGN KEY (invoice_id) REFERENCES public.invoice(id);
ADD CONSTRAINT "transaction_invoiceId_fkey" FOREIGN KEY ("invoiceId") REFERENCES public.invoice(id);
--
-- Name: transaction transaction_object_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: transaction transaction_objectId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.transaction
ADD CONSTRAINT transaction_object_id_fkey FOREIGN KEY (object_id) REFERENCES public.object(id);
ADD CONSTRAINT "transaction_objectId_fkey" FOREIGN KEY ("objectId") REFERENCES public.object(id);
--
-- Name: transactions_to_objects transactions_to_objects_object_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: transactionsToObjects transactionsToObjects_objectId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.transactions_to_objects
ADD CONSTRAINT transactions_to_objects_object_id_fkey FOREIGN KEY (object_id) REFERENCES public.object(id);
ALTER TABLE ONLY public."transactionsToObjects"
ADD CONSTRAINT "transactionsToObjects_objectId_fkey" FOREIGN KEY ("objectId") REFERENCES public.object(id);
--
-- Name: transactions_to_objects transactions_to_objects_transaction_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
-- Name: "transactionsToObjects" transactionsToObjects_transactionId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.transactions_to_objects
ADD CONSTRAINT transactions_to_objects_transaction_id_fkey FOREIGN KEY (transaction_id) REFERENCES public.transaction(id);
ALTER TABLE ONLY public."transactionsToObjects"
ADD CONSTRAINT "transactionsToObjects_transactionId_fkey" FOREIGN KEY ("transactionId") REFERENCES public.transaction(id);
--

View File

@ -20,20 +20,20 @@ SET client_min_messages = warning;
SET row_security = off;
--
-- Data for Name: supplier_type; Type: TABLE DATA; Schema: public; Owner: -
-- Data for Name: supplierType; Type: TABLE DATA; Schema: public; Owner: -
--
COPY public.supplier_type (id, name) FROM stdin;
COPY public."supplierType" (id, name) FROM stdin;
1 Company
2 Person
\.
--
-- Name: supplier_type_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
-- Name: supplierType_id_seq; Type: SEQUENCE SET; Schema: public; Owner: -
--
SELECT pg_catalog.setval('public.supplier_type_id_seq', 2, true);
SELECT pg_catalog.setval('public."supplierType_id_seq"', 2, true);
--

View File

@ -1,26 +1,9 @@
import _ from 'lodash'
import knex from 'knex'
// @ts-ignore
import pg from 'pg'
import env from '../env.ts'
const queryProto = pg.Query.prototype
const handleRowDescription = queryProto.handleRowDescription
queryProto.handleRowDescription = function (msg: { fields: { name: string }[] }) {
msg.fields.forEach((field: { name: string }) => {
field.name = _.camelCase(field.name)
})
return handleRowDescription.call(this, msg)
}
export default knex({
client: 'pg',
wrapIdentifier: (value, origImpl) => (value === '*' ? value : origImpl(_.snakeCase(value))),
connection: {
database: env.PGDATABASE,
host: env.PGHOST,

View File

@ -160,7 +160,7 @@ export default async function parseStream(stream: ReadableStream, decoder: Decod
if (yearNumber !== 0) continue
currentYear = (
await trx('financial_year')
await trx('financialYear')
.insert({ year: startDate.slice(0, 4), startDate, endDate })
.returning('*')
)[0]
@ -244,7 +244,7 @@ export default async function parseStream(stream: ReadableStream, decoder: Decod
const objectId = (
await trx('object')
.first('object.id')
.innerJoin('dimension', 'object.dimension_id', 'dimension.id')
.innerJoin('dimension', 'object.dimensionId', 'dimension.id')
.where({
'object.number': objectNumber,
'dimension.number': dimensionNumber,

View File

@ -23,7 +23,7 @@ const entryRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
return knex('entry AS e')
.select('e.*')
.sum('t.amount AS amount')
.innerJoin('transaction AS t', 'e.id', 't.entry_id')
.innerJoin('transaction AS t', 'e.id', 't.entryId')
.orderBy('e.id')
.where({ financialYearId, journalId })
.andWhere('t.amount', '>', 0)
@ -46,14 +46,14 @@ const entryRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
.select(knex.raw('json_agg(transactions)'))
.from(
knex('transaction')
.select('account_number AS accountNumber', 'object_id AS objectId')
.select('accountNumber', 'objectId')
.where('transaction.entryId', knex.ref('e.id'))
.as('transactions'),
),
})
.sum('t.amount AS amount')
.innerJoin('journal AS j', 'e.journalId', 'j.id')
.innerJoin('transaction AS t', 'e.id', 't.entry_id')
.innerJoin('transaction AS t', 'e.id', 't.entryId')
.where('e.id', req.params.id)
.andWhere('t.amount', '>', 0)
.groupBy('e.id', 'j.identifier')

View File

@ -41,7 +41,7 @@ const invoiceRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
),
transactions: knex
.select(knex.raw('json_agg(transactions)'))
.from(knex.select('*').from('transaction AS t').where('t.invoice_id', knex.ref('i.id')).as('transactions')),
.from(knex.select('*').from('transaction AS t').where('t.invoiceId', knex.ref('i.id')).as('transactions')),
})
.leftOuterJoin('financialYear AS fy', 'i.financialYearId', 'fy.id')
.orderBy('i.invoiceDate')
@ -99,7 +99,7 @@ const invoiceRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
),
transactions: knex
.select(knex.raw('json_agg(transactions)'))
.from(knex.select('*').from('transaction AS t').where('t.invoice_id', knex.ref('i.id')).as('transactions')),
.from(knex.select('*').from('transaction AS t').where('t.invoiceId', knex.ref('i.id')).as('transactions')),
})
.leftOuterJoin('financialYear AS fy', 'i.financialYearId', 'fy.id')
.where('i.id', req.params.id)

View File

@ -37,7 +37,7 @@ const journalRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
const trx = await knex.transaction()
await trx('invoice').update('supplier_id', req.body.ids[0]).whereIn('supplierId', req.body.ids.slice(1))
await trx('invoice').update('supplierId', req.body.ids[0]).whereIn('supplierId', req.body.ids.slice(1))
await trx('supplier').delete().whereIn('id', req.body.ids.slice(1))
// 556744-4301

View File

@ -37,7 +37,7 @@ const transactionRoutes: FastifyPluginCallbackTypebox = (fastify, _, done) => {
't.invoiceId',
'e.description AS entryDescription',
)
.innerJoin('entry AS e', 't.entry_id', 'e.id')
.innerJoin('entry AS e', 't.entryId', 'e.id')
.where(query)
},
})

View File

@ -18,7 +18,7 @@ export interface Entry {
transactionDate: string
entryDate: string
transactions: {
account_number: number
accountNumber: number
description: string
amount: number
}[]
@ -40,10 +40,10 @@ export type Invoice = {
amount: number
files?: { filename: string }[]
transactions?: {
account_number: number
accountNumber: number
amount: number
description: number
entry_id: number
entryId: number
}[]
}