Files
tilbudgivern/backend/package.json
T
alexpolo1andAI Assistant 80632c996b feat: Complete Ordrestyring GraphQL integration with automatic offer creation
FEATURES IMPLEMENTED:
 Full GraphQL integration with Ordrestyring API
 Automatic offer creation from Tilbudsgiveren quotes
 Customer management (find existing or create new)
 Task/Opgave management with full quote description
 Material lines (tilbudslinjer) with pricing
 Internal notes in bemærkninger field
 Department assignment (Tømrer = ID 2)
 Status management (Tilbudsgiver Oprettet Tilbud)

KEY COMPONENTS:

1. OrdrestyringQuoteService (backend/src/services/ordrestyringQuoteService.js)
   - generateDetailedQuoteDescription(): Creates formatted quote text
   - findOrCreateCustomer(): Handles customer, contact, delivery address
   - createOfferLines(): Updates default task & adds material lines
   - sendQuoteToOrdrestyring(): Main orchestration method
   - getOfferWithTasks(): Query offers with task details

2. Smart Task Management:
   - Finds and updates existing default 'Opgave 1' task
   - Renames to 'Tilbudsgivertekst' for clarity
   - Adds full 2000+ character quote description
   - Creates material lines under the task
   - Fallback: Creates new task if none exists

3. GraphQL Mutations & Queries:
   - createOffer: Creates offer with customer, status, department
   - updateOfferTask: Updates existing task with description
   - createOfferTask: Fallback for new task creation
   - createOfferLine: Adds material lines with pricing
   - Proper error handling and logging throughout

4. Database Integration:
   - Migration: add_ordrestyring_columns.sql
   - Tracks ordrestyring_offer_id, ordrestyring_offer_number
   - Status synchronization with ordrestyring_status
   - Timestamp tracking with ordrestyring_sent_at

5. Route Updates (backend/routes/ordrestyring.js):
   - POST /api/ordrestyring/send-quote-graphql
   - Optional customerId parameter (uses existing or creates new)
   - Validation for projectId and calculationId
   - Returns complete offer details

TECHNICAL HIGHLIGHTS:

• GraphQL Client: graphql-request v7.3.1
• API Endpoint: https://graphql.ordrestyring.dk/graphql
• Authentication: Bearer token in headers
• Error Handling: Graceful fallbacks, detailed logging
• Field Discovery: Used introspection to find correct types
  - UpdateOfferTaskInput (not OfferTaskInput)
  - Task fields: header & text (not name & description)
  - productNumber required for offer lines

TESTING:

• Test scripts: test_roesevangen_ordrestyring.py
• Verification: test_check_offer.js
• Live testing with Project 22 (Røsevangen 44)
• Confirmed: Single task with full description
• Confirmed: 10 material lines with correct pricing
• Confirmed: Department, status, and internal notes working

RESULT:
Complete end-to-end integration from Tilbudsgiveren → Ordrestyring
- Creates professional offers with all data
- Single 'Tilbudsgivertekst' task (not duplicate Opgave 1)
- Full quote description visible in task
- Material lines with quantities and prices
- Ready for production use

Co-authored-by: AI Assistant <[email protected]>
2025-10-31 21:19:00 +00:00

38 lines
905 B
JSON

{
"name": "tilbudgivern-backend",
"version": "1.0.0",
"description": "Backend for AI-baseret tilbudsberegner",
"main": "src/index.js",
"scripts": {
"dev": "nodemon src/init.js",
"start": "node src/init.js",
"build": "echo 'No build step needed for Node.js'",
"test": "jest"
},
"dependencies": {
"axios": "^1.12.2",
"cheerio": "^1.1.2",
"cors": "^2.8.5",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"graphql": "^16.8.1",
"graphql-request": "^6.1.0",
"helmet": "^7.1.0",
"joi": "^17.11.0",
"multer": "^2.0.2",
"mysql2": "^3.14.5",
"openai": "^4.20.1",
"pdf-parse": "^1.1.1",
"pdf2pic": "^3.2.0",
"rate-limiter-flexible": "^2.4.1",
"sharp": "^0.34.3",
"tesseract.js": "^6.0.1",
"winston": "^3.11.0"
},
"devDependencies": {
"jest": "^29.7.0",
"nodemon": "^3.0.2",
"supertest": "^6.3.3"
}
}