# Job Folder Integration Module Automatically creates OneDrive folders with share links when PocketBase job records are created. ## Installation ```bash cd extracted-graph-logic bun install ``` ## Integration ### 1. Import in server.ts ```typescript import { processNewJobRecord } from './extracted-graph-logic/post-record-integration.js'; ``` ### 2. Call after PocketBase record creation ```typescript const graphToken = await getGraphToken(); const folderResult = await processNewJobRecord(record, graphToken); if (folderResult.success) { record.Job_Folder_Link = folderResult.shareLink || ''; } await addToExcel(record, record.id); ``` ## What It Does 1. Receives PocketBase record + Graph API token 2. Creates folder: `{Job_Number} - {Job_Name} - {Job_Address} - {Company_Client}` 3. Creates "Managers Info" subfolder 4. Generates organization-wide share link 5. Returns folder details and link ## Module Files - **post-record-integration.js** - Main entry point, exports processNewJobRecord() - **job-folder-integration.js** - Core Graph API logic, exports createJobFolderAndGetLink() - **config.js** - Production configuration: - DRIVE_ID: b!9YOqqr2xM0G2DFBwMEJYY4UzQgocFddEtpLYWuS9_AtkCKl2q8yjQJteQ7Ti4QSx - PARENT_ITEM_ID: 01SPNXLDW3Y56HAWK5CNAJ4YJLLSQCUCJ7 - CLIENT_ID: 3c846e71-9609-40e1-b458-0eb805e21b9f - **package.json** - Dependencies (node-fetch@2.7.0) ## Return Values ### On Success ```javascript { success: true, jobNumber: "12345", jobFullName: "New Construction - 123 Main St - ABC Corp", shareLink: "https://...", mainFolderId: "...", mainFolderName: "...", subFolderId: "...", folderPath: "..." } ``` ### On Failure ```javascript { success: false, error: "error message", jobNumber: "12345", shareLink: null } ``` ## Configuration Edit config.js to change OneDrive location. Current values point to Cardoza Construction production SharePoint/OneDrive. ## Error Handling - If folder creation fails, job is still created in PocketBase and synced to Excel - Share link will be null on failure - Errors logged with `[Job Folder Integration]` prefix ## Dependencies - node-fetch@2.7.0 (for Graph API calls) - Graph API token from your server ## Status Production-ready. Uses actual OneDrive/SharePoint IDs from Job Creation Form environment.