Files
eve-industrializer/src/services/billItemService.ts

21 lines
628 B
TypeScript

import { IndBillitemRecord } 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<IndBillitemRecord, 'id' | 'created' | 'updated'>,
type: 'billOfMaterials' | 'consumedMaterials'
): Promise<IndBillitemRecord> {
// Create the bill item
const createdItem = await pb.collection<IndBillitemRecord>('ind_billItem').create(billItem);
const currentBillItems = job[type] || [];
await updateJob(job.id, {
[type]: [...currentBillItems, createdItem.id]
});
return createdItem;
}