# Ordrestyring API Inventory - Current Usage Analysis **Date**: October 23, 2025 **Purpose**: Complete inventory of all Ordrestyring API endpoints currently in use **Status**: 🔍 In Progress --- ## Summary Statistics - **Total Files Using Ordrestyring API**: 10+ files - **Backend Services**: 3 (ordrestyringService, ordrestyringSyncService, enhancedOrderDataService) - **Frontend Components**: 2 (FinalReview, LaborInput) - **API Routes**: 1 (ordrestyring.js) - **Test/Import Scripts**: 5 (can be archived) - **Main Server**: 1 (unified-server.js - mixed usage) --- ## 1. Backend Services ### 1.1 ordrestyringService.js (PRIMARY SERVICE) **File**: `backend/src/services/ordrestyringService.js` **Lines**: 790 total **Status**: 🟡 MIXED - Both REST and GraphQL implementations #### REST v1 Endpoints (DEPRECATED) - `this.restApiUrl = 'https://api.ordrestyring.dk'` - **Action**: DELETE - No longer maintained #### REST v2 Endpoints (TO BE REPLACED) - `this.restApiV2Url = 'https://v2.api.ordrestyring.dk'` - Used by: `makeAPIRequest()` method - **Action**: REPLACE with GraphQL #### GraphQL Endpoints (PARTIALLY IMPLEMENTED) - `this.graphqlApiUrl = 'https://beta7-api.ordrestyring.dk/graphql'` - ⚠️ **Issue**: Using BETA endpoint, should be production - ✅ **Has**: `makeGraphQLRequest()` method - **Action**: UPDATE to production endpoint + expand usage #### Methods Inventory Need to analyze each method and categorize: - [ ] Line 30-60: `makeAPIRequest()` - REST v2 - REPLACE - [ ] Line 62-95: `makeGraphQLRequest()` - GraphQL - KEEP & ENHANCE - [ ] Lines 100+: Individual endpoint methods - TO BE ANALYZED **Priority**: HIGH - This is the main service layer --- ### 1.2 ordrestyringSyncService.js **File**: `backend/src/services/ordrestyringSyncService.js` **Status**: 🔴 REST v2 ONLY #### Configuration - Line 12: `this.apiBaseUrl = 'https://v2.api.ordrestyring.dk'` - Line 11: `this.apiToken = process.env.ORDRESTYRING_API_TOKEN || ''` #### Purpose - Data synchronization between systems - Likely has polling/webhook logic **Action Required**: - [ ] Audit all methods - [ ] Find GraphQL equivalents - [ ] Consider merging into main ordrestyringService - [ ] DELETE if redundant **Priority**: MEDIUM --- ### 1.3 enhancedOrderDataService.js **File**: `backend/src/services/enhancedOrderDataService.js` **Status**: 🔴 REST v2 ONLY #### Configuration - Line 7: `this.apiBase = 'https://v2.api.ordrestyring.dk'` #### Purpose - Enhanced order data retrieval - Additional data enrichment **Action Required**: - [ ] Audit all methods - [ ] Check if functionality exists in GraphQL - [ ] Consider merging into main service - [ ] DELETE if redundant **Priority**: MEDIUM --- ## 2. API Routes ### 2.1 ordrestyring.js **File**: `backend/routes/ordrestyring.js` **Status**: 🔴 LEGACY REST v1 #### Endpoints Found ##### DELETE Case (Line 344) ```javascript await axios.delete(`https://api.ordrestyring.dk/v1/cases/${caseNumber}`, { headers: { Authorization: `Bearer ${apiToken}` } }) ``` - **Purpose**: Delete case by case number - **Status**: LEGACY v1 API - **GraphQL Equivalent**: `mutation deleteCase($id: Int!)` - **Priority**: HIGH - Delete operation needs careful handling - **Action**: REPLACE with GraphQL mutation + add safety checks ##### GET Cases (Line 404) ```javascript const ordrestyringSvar = await axios.get('https://api.ordrestyring.dk/v1/cases', { headers: { Authorization: `Bearer ${apiToken}` } }) ``` - **Purpose**: Fetch all cases - **Status**: LEGACY v1 API - **GraphQL Equivalent**: `query cases($pagination: Pagination)` - **Priority**: HIGH - Core functionality - **Action**: REPLACE with GraphQL query **Priority**: HIGH - Main API routes --- ## 3. Frontend Components ### 3.1 FinalReview.js **File**: `frontend/src/components/FinalReview.js` **Line**: 84 **Status**: 🔴 CRITICAL - NON-EXISTENT ENDPOINT #### Current Implementation ```javascript const response = await fetch(`${apiBaseUrl}/api/ordrestyring/submit-quote`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(orderData) }); ``` #### Issues - ⚠️ **Endpoint does NOT exist in backend** - ⚠️ **Returns error or fails silently** - ⚠️ **No offers created in Ordrestyring** #### Required Implementation **Backend Endpoint**: `/api/ordrestyring/offers/create` **GraphQL Mutation**: `createOffer` **Script Reference**: `apitest/examples/mutation_create_offer.sh` **Data Mapping Required**: ```javascript Frontend → GraphQL { customer: { id, name, ... } → customerId materials: [...] → offerLines (with productId) labor: { tasks: [...] } → offerLines (with isLabor flag) totals: { ... } → calculated automatically quote: { validUntil, ... } → metadata } ``` **Priority**: 🔴 CRITICAL - Core business functionality **Estimated Effort**: 1-2 days **Dependencies**: - GraphQL client setup - CREATE_OFFER_MUTATION definition - Input validation - Error handling --- ### 3.2 LaborInput.js **File**: `frontend/src/components/LaborInput.js` **Lines**: 87, 290 **Status**: 🟡 REST ENDPOINT #### Current Implementation ```javascript // Line 87 const workBreakdownResponse = await fetch( `${apiBaseUrl}/api/ordrestyring/case/${caseNumber}/work-breakdown` ); // Line 290 const response = await fetch( `${apiBaseUrl}/api/ordrestyring/case/${caseNumber}/work-breakdown` ); ``` #### Purpose - Fetch work breakdown for a case - Display hours, tasks, materials #### GraphQL Equivalent **Query**: `case(id: $id)` with nested fields: ```graphql query GetCaseWorkBreakdown($caseId: Int!) { case(id: $caseId) { id caseNumber caseActivities { id description hours employee { id name } hourType { id name rate } } caseMaterials { id product { id name } quantity unitPrice total } } } ``` **Script Reference**: `apitest/examples/curl_case_activities.sh`, `curl_case_materials.sh` **Priority**: MEDIUM **Estimated Effort**: 4-6 hours --- ## 4. Unified Server (Main Server) ### 4.1 unified-server.js **File**: `unified-server.js` **Status**: 🟡 MIXED - Configuration + Active Endpoints #### API Configuration (Lines 8314-8321) ```javascript v1: 'https://api.ordrestyring.dk', v2: 'https://v2.api.ordrestyring.dk' // ... graphql: { endpoint: 'https://beta7-api.ordrestyring.dk/graphql', graphiql: 'https://beta7-api.ordrestyring.dk/graphiql' } ``` **Issues**: - Still referencing deprecated v1 - Still referencing v2 (to be replaced) - GraphQL uses BETA endpoint **Action**: UPDATE configuration to production GraphQL only #### Active Endpoints (Lines 9501-9519) ##### Calendar Endpoint (Line 9511) ```javascript axios.get(`https://v2.api.ordrestyring.dk/calendar?start=${start}&stop=${stop}...`) ``` - **GraphQL Equivalent**: `query calendar($start: String!, $stop: String!)` - **Script Reference**: `apitest/examples/curl_calendar.sh` - **Priority**: HIGH - Used for calendar display ##### Hours Endpoint (Line 9515) ```javascript axios.get(`https://v2.api.ordrestyring.dk/hours?start_time-min=${start}...`) ``` - **GraphQL Equivalent**: `query hours($filter: HourFilter)` - **Script Reference**: `apitest/examples/curl_hours.sh` - **Priority**: HIGH - Time tracking ##### Planned Time Endpoint (Line 9519) ```javascript axios.get(`https://v2.api.ordrestyring.dk/planned-time?time_start-min=${start}...`) ``` - **GraphQL Equivalent**: `query plannedTime($filter: PlannedTimeFilter)` - **Script Reference**: `apitest/examples/curl_planned_time.sh` - **Priority**: HIGH - Schedule planning **Priority**: HIGH - Main server endpoints --- ## 5. Test & Import Scripts (Archive Candidates) ### 5.1 test_ordrestyring_import.js - **Line 9**: `const API_BASE = 'https://v2.api.ordrestyring.dk';` - **Purpose**: Test import functionality - **Action**: ARCHIVE (no longer needed after GraphQL migration) ### 5.2 comprehensive_ordrestyring_import.js - **Line 31**: `baseUrl: 'https://v2.api.ordrestyring.dk'` - **Purpose**: Comprehensive data import - **Action**: ARCHIVE or UPDATE to GraphQL for ongoing use ### 5.3 ordrestyring_full_import.js - **Line 31**: `baseUrl: 'https://api.ordrestyring.dk/v2'` - **Purpose**: Full data import - **Action**: ARCHIVE ### 5.4 complete_import.js - **Line 9**: `const API_BASE = 'https://v2.api.ordrestyring.dk';` - **Purpose**: Complete import process - **Action**: ARCHIVE ### 5.5 test_all_calendar_sources.js - **Line 4**: `const baseURL = 'https://v2.api.ordrestyring.dk';` - **Purpose**: Test calendar data sources - **Action**: ARCHIVE or UPDATE for GraphQL testing **Priority**: LOW - Can be archived once migration complete --- ## 6. Detailed Endpoint Migration Map ### Priority 1: CRITICAL (Must Migrate First) | Current Endpoint | File | Line | GraphQL Equivalent | Script Reference | Effort | |-----------------|------|------|-------------------|------------------|--------| | POST /submit-quote | FinalReview.js | 84 | createOffer mutation | mutation_create_offer.sh | 1-2 days | | GET /cases | ordrestyring.js | 404 | cases query | curl_cases.sh | 4 hours | | DELETE /cases/:id | ordrestyring.js | 344 | deleteCase mutation | mutation_delete_case.sh | 6 hours | ### Priority 2: HIGH (Core Functionality) | Current Endpoint | File | Line | GraphQL Equivalent | Script Reference | Effort | |-----------------|------|------|-------------------|------------------|--------| | GET /calendar | unified-server.js | 9511 | calendar query | curl_calendar.sh | 4 hours | | GET /hours | unified-server.js | 9515 | hours query | curl_hours.sh | 4 hours | | GET /planned-time | unified-server.js | 9519 | plannedTime query | curl_planned_time.sh | 4 hours | | GET /work-breakdown | LaborInput.js | 87, 290 | case query (nested) | curl_case_activities.sh | 6 hours | ### Priority 3: MEDIUM (Service Layer) | Service | File | Status | Action | Effort | |---------|------|--------|--------|--------| | ordrestyringService | ordrestyringService.js | Mixed | Refactor to GraphQL only | 2 days | | ordrestyringSyncService | ordrestyringSyncService.js | REST v2 | Migrate or merge | 1 day | | enhancedOrderDataService | enhancedOrderDataService.js | REST v2 | Migrate or merge | 1 day | ### Priority 4: LOW (Cleanup) | Item | Action | Effort | |------|--------|--------| | Test scripts | Archive to archive/ folder | 1 hour | | Legacy v1 config | Remove from code | 2 hours | | REST v2 config | Remove after migration | 2 hours | | Documentation | Update with GraphQL | 4 hours | --- ## 7. GraphQL Queries/Mutations Available **From apitest folder**: 565 scripts (99.8% API coverage) ### Queries (255 scripts) **Most Relevant**: - ✅ `curl_cases.sh` - List cases - ✅ `curl_case_by_id.sh` - Get case by ID - ✅ `curl_case_activities.sh` - Case activities - ✅ `curl_case_materials.sh` - Case materials - ✅ `curl_calendar.sh` - Calendar events - ✅ `curl_hours.sh` - Hours/time tracking - ✅ `curl_planned_time.sh` - Planned time - ✅ `curl_offers.sh` - List offers - ✅ `curl_offer.sh` - Get single offer - ✅ `curl_customers.sh` - List customers - ✅ `curl_products.sh` - List products ### Mutations (310 scripts) **Most Relevant**: - ✅ `mutation_create_offer.sh` - **CREATE OFFER** (CRITICAL!) - ✅ `mutation_update_offer.sh` - Update offer - ✅ `mutation_delete_case.sh` - Delete case - ✅ `mutation_create_case.sh` - Create case - ✅ `mutation_update_case.sh` - Update case - ✅ `mutation_send_offer_via_email.sh` - Send offer - ✅ `mutation_mark_message_as_read.sh` - Mark read --- ## 8. Authentication Analysis ### Current Token ```javascript const apiToken = process.env.ORDRESTYRING_API_TOKEN || ''; ``` ### REST v2 Auth (Current) ```javascript auth: { username: apiToken, password: 'x' } ``` ### GraphQL Auth (Current - BETA) ```javascript headers: { 'Authorization': `Bearer ${apiToken}` } ``` ### Issues Found - ⚠️ Hardcoded fallback token in code (security risk) - ⚠️ Using BETA GraphQL endpoint - ⚠️ Error messages suggest REST token ≠ GraphQL token ### Action Required - [ ] Verify token works with production GraphQL: `https://graphql.ordrestyring.dk/graphql` - [ ] Request new GraphQL-specific token if needed - [ ] Remove hardcoded fallback token - [ ] Use environment variable only - [ ] Document token rotation procedure --- ## 9. Risk Assessment by Endpoint ### High Risk (Data Modification) | Endpoint | Risk | Mitigation | |----------|------|------------| | createOffer | Data corruption if mapping wrong | Extensive testing, validation | | deleteCase | Accidental deletion | Add confirmation, soft delete | | updateCase | Data overwrite | Backup before update, validate | ### Medium Risk (Data Retrieval) | Endpoint | Risk | Mitigation | |----------|------|------------| | cases query | Performance issues | Pagination, caching | | calendar query | Missing data | Fallback handling | | hours query | Incorrect calculations | Unit tests | ### Low Risk (Read-Only) | Endpoint | Risk | Mitigation | |----------|------|------------| | List queries | None | Standard error handling | | Get by ID | 404 errors | Graceful error messages | --- ## 10. Next Steps ### Immediate (This Week) 1. ✅ **Test GraphQL Authentication** - Verify production endpoint: `https://graphql.ordrestyring.dk/graphql` - Test with current token - Request new token if needed 2. ✅ **Review createOffer Mutation** - Study `apitest/examples/mutation_create_offer.sh` - Understand input format - Map FinalReview data to GraphQL input 3. ✅ **Setup GraphQL Client** - Install `graphql-request` or `@apollo/client` - Create client configuration - Test connection ### Short Term (Next Week) 4. ✅ **Implement createOffer Endpoint** - Backend: `/api/ordrestyring/offers/create` - Frontend: Update FinalReview.js - Test thoroughly 5. ✅ **Migrate Calendar Endpoints** - Replace REST with GraphQL in unified-server.js - Test calendar display 6. ✅ **Migrate Cases Endpoints** - Replace in ordrestyring.js routes - Update error handling ### Medium Term (Weeks 2-3) 7. ✅ **Refactor Services** - Clean up ordrestyringService.js - Merge redundant services - Remove deprecated code 8. ✅ **Comprehensive Testing** - Unit tests for all GraphQL calls - Integration tests - E2E tests ### Long Term (Week 4+) 9. ✅ **Production Deployment** - Staged rollout - Monitoring - Documentation 10. ✅ **Cleanup** - Archive test scripts - Remove REST code - Update documentation --- ## 11. Questions & Blockers ### ❓ Questions to Answer - [ ] What is the production GraphQL endpoint URL? - [ ] Does current token work with production GraphQL? - [ ] Are there any rate limits on GraphQL API? - [ ] What is the error response format for GraphQL? - [ ] Are there any breaking changes between beta and production? - [ ] Do we need separate tokens for staging/production? - [ ] What fields are required vs optional in createOffer? - [ ] How are errors returned for mutations? ### 🚧 Potential Blockers - [ ] GraphQL authentication might require new token - [ ] Production endpoint might not be available yet - [ ] Schema differences between beta and production - [ ] Missing required fields in current data structure - [ ] Performance issues with complex queries - [ ] Rate limiting on GraphQL API --- ## 12. Success Metrics ### Code Quality - Zero REST v1 references - Zero REST v2 references - All services use GraphQL only - Test coverage > 80% ### Functionality - FinalReview successfully creates offers - All queries return expected data - All mutations execute successfully - Error handling works properly ### Performance - GraphQL response time < REST v2 - No increase in error rates - Successful migration of all endpoints --- **Status**: 🔍 In Progress **Next Update**: After authentication testing **Owner**: Development Team --- ## Appendix: File Locations ### Backend - `backend/src/services/ordrestyringService.js` - `backend/src/services/ordrestyringSyncService.js` - `backend/src/services/enhancedOrderDataService.js` - `backend/routes/ordrestyring.js` - `unified-server.js` ### Frontend - `frontend/src/components/FinalReview.js` - `frontend/src/components/LaborInput.js` ### Scripts (To Archive) - `test_ordrestyring_import.js` - `comprehensive_ordrestyring_import.js` - `ordrestyring_full_import.js` - `complete_import.js` - `test_all_calendar_sources.js` ### GraphQL Resources - `apitest/examples/` - 565 script files - `apitest/API_INTEGRATION_GUIDE.md` - Integration guide - `apitest/outputs/` - Example responses