
- New quarterly_orders table with validation and constraints - Full CRUD API endpoints for quarterly orders management - Import functionality for bulk quarterly data from JSON - Python scripts for data migration and database import - Consistent validation for quarterly types and amounts - Follows established DRY/KISS architectural patterns
44 lines
1.5 KiB
Python
44 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
import json
|
|
import requests
|
|
import sys
|
|
|
|
def import_quarterlies():
|
|
# Read the quarterly data
|
|
with open('/home/rockvilleav/Nextcloud/quarterlies_orders_autosave.json', 'r') as f:
|
|
data = json.load(f)
|
|
|
|
# Transform the data to match our API format
|
|
import_data = {
|
|
"orders": []
|
|
}
|
|
|
|
for order in data["orders"]:
|
|
import_data["orders"].append({
|
|
"name": order["name"],
|
|
"type": order["type"],
|
|
"amount": order["amount"]
|
|
})
|
|
|
|
# Print the data that will be imported
|
|
print(f"Importing {len(import_data['orders'])} quarterly orders...")
|
|
print("\nFirst few orders:")
|
|
for i, order in enumerate(import_data["orders"][:5]):
|
|
print(f" {i+1}. {order['name']} - {order['type']} (x{order['amount']})")
|
|
|
|
if len(import_data["orders"]) > 5:
|
|
print(f" ... and {len(import_data['orders']) - 5} more")
|
|
|
|
# Save the transformed data for manual import via API
|
|
with open('/opt/rtsda/church-api/quarterly_import_data.json', 'w') as f:
|
|
json.dump(import_data, f, indent=2)
|
|
|
|
print(f"\nTransformed data saved to: /opt/rtsda/church-api/quarterly_import_data.json")
|
|
print("You can now use this file to import via the API endpoint:")
|
|
print("curl -X POST http://localhost:3002/api/admin/quarterlies/import \\")
|
|
print(" -H 'Content-Type: application/json' \\")
|
|
print(" -H 'Authorization: Bearer YOUR_JWT_TOKEN' \\")
|
|
print(" -d @quarterly_import_data.json")
|
|
|
|
if __name__ == "__main__":
|
|
import_quarterlies() |