Implement bill item service
This commit is contained in:
20
src/services/billItemService.ts
Normal file
20
src/services/billItemService.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
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;
|
||||
}
|
Reference in New Issue
Block a user