From 70d6979b4766397042a71b7f45b37e5dbb84c35b Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Fri, 4 Jul 2025 16:19:18 +0200 Subject: [PATCH] Add logs to services --- src/services/billItemService.ts | 5 +- src/services/jobDataService.ts | 80 ------------------------------ src/services/jobService.ts | 9 ++++ src/services/transactionService.ts | 4 +- 4 files changed, 15 insertions(+), 83 deletions(-) delete mode 100644 src/services/jobDataService.ts diff --git a/src/services/billItemService.ts b/src/services/billItemService.ts index 793e120..0b0d413 100644 --- a/src/services/billItemService.ts +++ b/src/services/billItemService.ts @@ -1,13 +1,14 @@ -import { IndBillitemRecord } from "@/lib/pbtypes"; +import { IndBillitemRecord, IndBillitemRecordNoId } from "@/lib/pbtypes"; import { IndJob } from "@/lib/types"; import pb from "@/lib/pocketbase"; import { updateJob } from "./jobService"; export async function addBillItem( job: IndJob, - billItem: Omit, + billItem: IndBillitemRecordNoId, type: 'billOfMaterials' | 'consumedMaterials' ): Promise { + console.log('Adding bill item:', billItem); // Create the bill item const createdItem = await pb.collection('ind_billItem').create(billItem); diff --git a/src/services/jobDataService.ts b/src/services/jobDataService.ts deleted file mode 100644 index 565fe6c..0000000 --- a/src/services/jobDataService.ts +++ /dev/null @@ -1,80 +0,0 @@ -import * as jobService from './jobService'; -import { IndTransactionRecord, IndBillitemRecord, IndJobRecord } from '@/lib/pbtypes'; -import pb from '@/lib/pocketbase'; -import { IndJob } from '@/lib/types'; - -export async function getJobsWithRelations(): Promise { - const jobs: IndJobRecord[] = await jobService.getJobs(); - const jobsWithRelations: IndJob[] = []; - - for (const job of jobs) { - const expenditures: IndTransactionRecord[] = []; - const income: IndTransactionRecord[] = []; - const billOfMaterials: IndBillitemRecord[] = []; - - // Fetch related transactions - if (job.expenditures) { - for (const txId of job.expenditures) { - try { - const tx = await pb.collection('ind_transaction').getOne(txId); - expenditures.push(tx as IndTransactionRecord); - } catch (e) { - console.warn('Failed to fetch expenditure transaction:', txId); - } - } - } - - if (job.income) { - for (const txId of job.income) { - try { - const tx = await pb.collection('ind_transaction').getOne(txId); - income.push(tx as IndTransactionRecord); - } catch (e) { - console.warn('Failed to fetch income transaction:', txId); - } - } - } - - // Fetch bill of materials - if (job.billOfMaterials) { - for (const itemId of job.billOfMaterials) { - try { - const item = await pb.collection('ind_billItem').getOne(itemId); - billOfMaterials.push(item as IndBillitemRecord); - } catch (e) { - console.warn('Failed to fetch bill item:', itemId); - } - } - } - - jobsWithRelations.push({ - ...job, - expenditures, - income, - billOfMaterials, - consumedMaterials: [] // This would need to be stored/retrieved differently - }); - } - - return jobsWithRelations; -} - -export async function getJobWithRelations(id: string): Promise { - const job = await jobService.getJob(id); - if (!job) return null; - - const expenditures: IndTransactionRecord[] = []; - const income: IndTransactionRecord[] = []; - const billOfMaterials: IndBillitemRecord[] = []; - - // Fetch related data similar to above - // ... (similar logic as in getJobsWithRelations) - - return { - ...job, - expenditures, - income, - billOfMaterials, - consumedMaterials: [] - }; -} diff --git a/src/services/jobService.ts b/src/services/jobService.ts index 3bc6187..e1627bf 100644 --- a/src/services/jobService.ts +++ b/src/services/jobService.ts @@ -8,19 +8,23 @@ export type { IndTransactionRecord as Transaction } from '../lib/pbtypes'; export type { IndBillitemRecord as BillItem } from '../lib/pbtypes'; export async function createJob(job: IndJobRecordNoId): Promise { + console.log('Creating job:', job); return await pb.collection('ind_job').create(job); } export async function getJobs(): Promise { + console.log('Getting jobs'); const result = await pb.collection('ind_job').getFullList(); return result; } export async function getJobsFull(): Promise { const jobs = await getJobs(); + console.log('Jobs:', jobs); return await Promise.all(jobs.map(toFullJob)); } export async function getJob(id: string): Promise { + console.log('Getting job:', id); try { return await pb.collection('ind_job').getOne(id); } catch (e) { @@ -29,20 +33,24 @@ export async function getJob(id: string): Promise { } } export async function getJobFull(id: string): Promise { + console.log('Getting job full:', id); const job = await getJob(id); if (!job) return null; return await toFullJob(job); } export async function updateJob(id: string, updates: Partial): Promise { + console.log('Updating job:', id, updates); return await pb.collection('ind_job').update(id, updates); } export async function deleteJob(id: string): Promise { + console.log('Deleting job:', id); await pb.collection('ind_job').delete(id); } async function toFullJob(job: IndJobRecord): Promise { + console.log('Converting job to full job:', job); const fullJob = { ...job, expenditures: [], @@ -99,6 +107,7 @@ async function toFullJob(job: IndJobRecord): Promise { } async function toHollowJob(job: IndJob): Promise { + console.log('Converting job to hollow job:', job); return { ...job, expenditures: job.expenditures.map(tx => tx.id), diff --git a/src/services/transactionService.ts b/src/services/transactionService.ts index d1fc045..bf55837 100644 --- a/src/services/transactionService.ts +++ b/src/services/transactionService.ts @@ -8,7 +8,7 @@ export async function createTransaction( transaction: IndTransactionRecordNoId, type: 'expenditure' | 'income' ): Promise { - console.log('Adding transaction:', transaction); + console.log('Creating transaction:', transaction); // Create the transaction transaction.job = job.id; const createdTransaction = await pb.collection('ind_transaction').create(transaction); @@ -26,10 +26,12 @@ export async function updateTransaction( transactionId: string, updates: Partial ): Promise { + console.log('Updating transaction:', transactionId, updates); await pb.collection('ind_transaction').update(transactionId, updates); } export async function deleteTransaction(job: IndJob, transactionId: string): Promise { + console.log('Deleting transaction:', transactionId); // Delete the transaction await pb.collection('ind_transaction').delete(transactionId);