Implement pocketbase API

This commit is contained in:
2025-07-04 15:07:01 +02:00
parent 7bc4724cc8
commit 7808907861
4 changed files with 139 additions and 112 deletions

View File

@@ -12,6 +12,7 @@ export enum Collections {
Otps = "_otps",
Superusers = "_superusers",
IndBillitem = "ind_billItem",
IndFacility = "ind_facility",
IndJob = "ind_job",
IndTransaction = "ind_transaction",
Regionview = "regionview",
@@ -105,6 +106,14 @@ export type IndBillitemRecord = {
updated?: IsoDateString
}
export type IndFacilityRecord = {
created?: IsoDateString
id: string
location: string
name: string
updated?: IsoDateString
}
export enum IndJobStatusOptions {
"Planned" = "Planned",
"Acquisition" = "Acquisition",
@@ -206,6 +215,7 @@ export type MfasResponse<Texpand = unknown> = Required<MfasRecord> & BaseSystemF
export type OtpsResponse<Texpand = unknown> = Required<OtpsRecord> & BaseSystemFields<Texpand>
export type SuperusersResponse<Texpand = unknown> = Required<SuperusersRecord> & AuthSystemFields<Texpand>
export type IndBillitemResponse<Texpand = unknown> = Required<IndBillitemRecord> & BaseSystemFields<Texpand>
export type IndFacilityResponse<Texpand = unknown> = Required<IndFacilityRecord> & BaseSystemFields<Texpand>
export type IndJobResponse<Texpand = unknown> = Required<IndJobRecord> & BaseSystemFields<Texpand>
export type IndTransactionResponse<Texpand = unknown> = Required<IndTransactionRecord> & BaseSystemFields<Texpand>
export type RegionviewResponse<Texpand = unknown> = Required<RegionviewRecord> & BaseSystemFields<Texpand>
@@ -223,6 +233,7 @@ export type CollectionRecords = {
_otps: OtpsRecord
_superusers: SuperusersRecord
ind_billItem: IndBillitemRecord
ind_facility: IndFacilityRecord
ind_job: IndJobRecord
ind_transaction: IndTransactionRecord
regionview: RegionviewRecord
@@ -239,6 +250,7 @@ export type CollectionResponses = {
_otps: OtpsResponse
_superusers: SuperusersResponse
ind_billItem: IndBillitemResponse
ind_facility: IndFacilityResponse
ind_job: IndJobResponse
ind_transaction: IndTransactionResponse
regionview: RegionviewResponse
@@ -258,6 +270,7 @@ export type TypedPocketBase = PocketBase & {
collection(idOrName: '_otps'): RecordService<OtpsResponse>
collection(idOrName: '_superusers'): RecordService<SuperusersResponse>
collection(idOrName: 'ind_billItem'): RecordService<IndBillitemResponse>
collection(idOrName: 'ind_facility'): RecordService<IndFacilityResponse>
collection(idOrName: 'ind_job'): RecordService<IndJobResponse>
collection(idOrName: 'ind_transaction'): RecordService<IndTransactionResponse>
collection(idOrName: 'regionview'): RecordService<RegionviewResponse>

6
src/lib/pocketbase.ts Normal file
View File

@@ -0,0 +1,6 @@
import PocketBase from 'pocketbase';
import { TypedPocketBase } from './pbtypes';
const pb = new PocketBase('https://evebase.site.quack-lab.dev') as TypedPocketBase;
export default pb;

View File

@@ -1,18 +1,30 @@
import type { IndFacilityRecord, IndFacilityResponse } from '../lib/pbtypes';
import pb from '../lib/pocketbase';
import { Facility } from './jobService';
export type { IndFacilityRecord as Facility } from '../lib/pbtypes';
// Stub functions - to be implemented with PocketBase
export const facilityService = {
async getFacilities(): Promise<Facility[]> {
// TODO: Implement with PocketBase
console.log('Fetching facilities');
// Mock data for development
return [
{ id: '1', name: 'Jita IV - Moon 4 - Caldari Navy Assembly Plant', location: 'Jita' },
{ id: '2', name: 'Amarr VIII (Oris) - Emperor Family Academy', location: 'Amarr' },
{ id: '3', name: 'Dodixie IX - Moon 20 - Federation Navy Assembly Plant', location: 'Dodixie' },
{ id: '4', name: 'Rens VI - Moon 8 - Brutor Tribe Treasury', location: 'Rens' },
{ id: '5', name: 'Hek VIII - Moon 12 - Boundless Creation Factory', location: 'Hek' }
];
export async function getFacilities(): Promise<IndFacilityResponse[]> {
const result = await pb.collection('ind_facility').getFullList();
return result as IndFacilityResponse[];
}
export async function getFacility(id: string): Promise<IndFacilityResponse | null> {
try {
return await pb.collection('ind_facility').getOne(id) as IndFacilityResponse;
} catch (e) {
if (e.status === 404) return null;
throw e;
}
};
}
export async function createFacility(facility: Omit<IndFacilityRecord, 'id' | 'created' | 'updated'>): Promise<IndFacilityResponse> {
return await pb.collection('ind_facility').create(facility) as IndFacilityResponse;
}
export async function updateFacility(id: string, updates: Partial<IndFacilityRecord>): Promise<IndFacilityResponse> {
return await pb.collection('ind_facility').update(id, updates) as IndFacilityResponse;
}
export async function deleteFacility(id: string): Promise<void> {
await pb.collection('ind_facility').delete(id);
}

View File

@@ -1,102 +1,98 @@
export interface Job {
id: string;
outputItem: {
id: string;
name: string;
quantity: number;
};
dates: {
creation: Date;
start: Date | null;
end: Date | null;
saleStart: Date | null;
saleEnd: Date | null;
};
status: 'Planned' | 'Transporting Materials' | 'Running' | 'Done' | 'Selling' | 'Closed';
facilityId: string;
expenditures: Transaction[];
income: Transaction[];
billOfMaterials: BillOfMaterialsItem[];
consumedMaterials: ConsumedMaterialsItem[];
import type { IndJobRecord, IndJobResponse, IndTransactionRecord, IndTransactionResponse, IndBillitemRecord, IndBillitemResponse } from '../lib/pbtypes';
import pb from '../lib/pocketbase';
export type { IndJobRecord as Job } from '../lib/pbtypes';
export type { IndTransactionRecord as Transaction } from '../lib/pbtypes';
export type { IndBillitemRecord as BillItem } from '../lib/pbtypes';
export async function createJob(job: Omit<IndJobRecord, 'id' | 'created' | 'updated'>): Promise<IndJobResponse> {
return await pb.collection('ind_job').create(job) as IndJobResponse;
}
export interface BillOfMaterialsItem {
name: string;
quantity: number;
export async function getJobs(): Promise<IndJobResponse[]> {
const result = await pb.collection('ind_job').getFullList();
return result as IndJobResponse[];
}
export interface ConsumedMaterialsItem {
name: string;
required: number;
}
export interface Transaction {
id: string;
date: Date;
quantity: number;
itemName: string;
unitPrice: number;
totalAmount: number;
buyer?: string;
location?: string;
corporation?: string;
wallet?: string;
}
export interface Facility {
id: string;
name: string;
location: string;
}
// Stub functions - to be implemented with PocketBase
export const jobService = {
async createJob(job: Omit<Job, 'id' | 'expenditures' | 'income'>): Promise<Job> {
// TODO: Implement with PocketBase
console.log('Creating job:', job);
return {
...job,
id: Date.now().toString(),
expenditures: [],
income: []
};
},
async getJobs(): Promise<Job[]> {
// TODO: Implement with PocketBase
console.log('Fetching jobs');
return [];
},
async getJob(id: string): Promise<Job | null> {
// TODO: Implement with PocketBase
console.log('Fetching job:', id);
return null;
},
async updateJob(id: string, updates: Partial<Job>): Promise<Job> {
// TODO: Implement with PocketBase
console.log('Updating job:', id, updates);
throw new Error('Not implemented');
},
async deleteJob(id: string): Promise<void> {
// TODO: Implement with PocketBase
console.log('Deleting job:', id);
},
async addTransaction(jobId: string, transaction: Omit<Transaction, 'id'>, type: 'expenditure' | 'income'): Promise<void> {
// TODO: Implement with PocketBase
console.log('Adding transaction:', jobId, transaction, type);
},
async updateTransaction(jobId: string, transactionId: string, updates: Partial<Transaction>): Promise<void> {
// TODO: Implement with PocketBase
console.log('Updating transaction:', jobId, transactionId, updates);
},
async deleteTransaction(jobId: string, transactionId: string): Promise<void> {
// TODO: Implement with PocketBase
console.log('Deleting transaction:', jobId, transactionId);
export async function getJob(id: string): Promise<IndJobResponse | null> {
try {
return await pb.collection('ind_job').getOne(id) as IndJobResponse;
} catch (e) {
if (e.status === 404) return null;
throw e;
}
};
}
export async function updateJob(id: string, updates: Partial<IndJobRecord>): Promise<IndJobResponse> {
return await pb.collection('ind_job').update(id, updates) as IndJobResponse;
}
export async function deleteJob(id: string): Promise<void> {
await pb.collection('ind_job').delete(id);
}
export async function addTransaction(
jobId: string,
transaction: Omit<IndTransactionRecord, 'id' | 'created' | 'updated'>,
type: 'expenditure' | 'income'
): Promise<void> {
// Create the transaction
const createdTransaction = await pb.collection('ind_transaction').create({
...transaction,
job: jobId
}) as IndTransactionResponse;
// Update the job to include the new transaction
const job = await getJob(jobId);
if (!job) throw new Error('Job not found');
const field = type === 'expenditure' ? 'expenditures' : 'income';
const currentIds = job[field] || [];
await updateJob(jobId, {
[field]: [...currentIds, createdTransaction.id]
});
}
export async function updateTransaction(
jobId: string,
transactionId: string,
updates: Partial<IndTransactionRecord>
): Promise<void> {
await pb.collection('ind_transaction').update(transactionId, updates);
}
export async function deleteTransaction(jobId: string, transactionId: string): Promise<void> {
// Delete the transaction
await pb.collection('ind_transaction').delete(transactionId);
// Update the job to remove the transaction reference
const job = await getJob(jobId);
if (!job) return;
// Remove from both expenditures and income arrays
const expenditures = (job.expenditures || []).filter(id => id !== transactionId);
const income = (job.income || []).filter(id => id !== transactionId);
await updateJob(jobId, {
expenditures,
income
});
}
export async function addBillItem(
jobId: string,
billItem: Omit<IndBillitemRecord, 'id' | 'created' | 'updated'>
): Promise<void> {
// Create the bill item
const createdItem = await pb.collection('ind_billItem').create(billItem) as IndBillitemResponse;
// Update the job to include the new bill item
const job = await getJob(jobId);
if (!job) throw new Error('Job not found');
const currentBillItems = job.billOfMaterials || [];
await updateJob(jobId, {
billOfMaterials: [...currentBillItems, createdItem.id]
});
}