9c73773c19
- Create Word document template with job information pre-populated - Auto-populate: Job Name, Address, Division, Client, Type, Status, Contact info - Include fillable fields: Scope, Vendors, Estimate Cost, Dates, Team Contacts, Notes - Document named [JobNumber] - Manager Info.docx for easy identification - Uses docx library to generate professional Word documents - Document uploaded automatically during job folder creation
Job Folder Integration Module
Automatically creates OneDrive folders with share links when PocketBase job records are created.
Installation
cd extracted-graph-logic
bun install
Integration
1. Import in server.ts
import { processNewJobRecord } from './extracted-graph-logic/post-record-integration.js';
2. Call after PocketBase record creation
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
- Receives PocketBase record + Graph API token
- Creates folder:
{Job_Number} - {Job_Name} - {Job_Address} - {Company_Client} - Creates "Managers Info" subfolder
- Generates organization-wide share link
- 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
{
success: true,
jobNumber: "12345",
jobFullName: "New Construction - 123 Main St - ABC Corp",
shareLink: "https://...",
mainFolderId: "...",
mainFolderName: "...",
subFolderId: "...",
folderPath: "..."
}
On Failure
{
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.