Files
Job-Form/extracted-graph-logic/README.md
T
aewing 340b7e0818 feat: implement dotenv secrets loading from /home/admin/secrets/.env
- Added dotenv package to load environment variables from absolute path
- Secrets now loaded automatically on app startup, no manual sourcing needed
- Secrets file secured with chmod 600, outside project directory
- Enables persistent secrets across service restarts
- Tested: Job submission flow working end-to-end with all steps completing
2025-12-20 04:56:16 +00:00

95 lines
2.3 KiB
Markdown

# 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.