- Implemented setup_ordrestyring_import.sh for initial database setup and data import from API. - Created sync_ordrestyring_data.sh for incremental updates to the local database. - Developed test_ordrestyring_import.js to validate API data import functionality. - Added test_enhanced_quote_demo.js to demonstrate the enhanced quote system using hybrid data sources. - Introduced test_ordrestyring_system.sh for comprehensive testing of the database system and API functionality. - Enhanced logging and error handling across scripts for better traceability. - Included analysis script creation for post-import data analysis.
62 lines
1.8 KiB
Bash
62 lines
1.8 KiB
Bash
#!/usr/bin/env bash
|
|
# API Client for Ordrestyring
|
|
|
|
# Configuration
|
|
DATA_DIR="${DATA_DIR:-./ordrestyring_export}"
|
|
REPORTS_DIR="${REPORTS_DIR:-./reports}"
|
|
|
|
# API endpoints
|
|
API_BASE="https://app.ordrestyring.dk/api/rest/v1"
|
|
|
|
# Fetch all cases from API
|
|
fetch_all_cases() {
|
|
local api_key="$1"
|
|
echo "Henter cases fra API..."
|
|
|
|
curl -s -H "Authorization: Bearer $api_key" \
|
|
-H "Content-Type: application/json" \
|
|
"$API_BASE/cases" > "$DATA_DIR/all_cases.json"
|
|
|
|
# Convert to JSONL format
|
|
if [[ -f "$DATA_DIR/all_cases.json" ]]; then
|
|
jq -c '.[]' "$DATA_DIR/all_cases.json" > "$DATA_DIR/all_cases.jsonl" 2>/dev/null || true
|
|
echo "Cases hentet: $(wc -l < "$DATA_DIR/all_cases.jsonl" 2>/dev/null || echo "0")"
|
|
fi
|
|
}
|
|
|
|
# Fetch hours data from API
|
|
fetch_hours_data() {
|
|
local api_key="$1"
|
|
echo "Henter timer data fra API..."
|
|
|
|
curl -s -H "Authorization: Bearer $api_key" \
|
|
-H "Content-Type: application/json" \
|
|
"$API_BASE/registrations/hours" > "$DATA_DIR/hours_data.json"
|
|
|
|
# Convert to JSONL format
|
|
if [[ -f "$DATA_DIR/hours_data.json" ]]; then
|
|
jq -c '.[]' "$DATA_DIR/hours_data.json" > "$DATA_DIR/hours_data.jsonl" 2>/dev/null || true
|
|
echo "Timer registreringer hentet: $(wc -l < "$DATA_DIR/hours_data.jsonl" 2>/dev/null || echo "0")"
|
|
fi
|
|
}
|
|
|
|
# Get case details by ID
|
|
get_case_details() {
|
|
local api_key="$1"
|
|
local case_id="$2"
|
|
|
|
curl -s -H "Authorization: Bearer $api_key" \
|
|
-H "Content-Type: application/json" \
|
|
"$API_BASE/cases/$case_id"
|
|
}
|
|
|
|
# Get hours for specific case
|
|
get_case_hours() {
|
|
local api_key="$1"
|
|
local case_id="$2"
|
|
|
|
curl -s -H "Authorization: Bearer $api_key" \
|
|
-H "Content-Type: application/json" \
|
|
"$API_BASE/cases/$case_id/hours"
|
|
}
|