summaryrefslogtreecommitdiff
path: root/official-site-scripts/add-event.sh
blob: 109c2c8237b47a2a785183fc486afee25fb11ec7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env bash
# Usage: bash add-event.sh <json-file>
# The JSON file should match the Event schema (see CLAUDE.md).
# id, createdAt, updatedAt, _version, _deleted, _lastChangedAt are auto-managed.
set -euo pipefail

REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
[ -f "$REPO_ROOT/.env" ] && set -a && source "$REPO_ROOT/.env" && set +a

ENDPOINT="${APP_SYNC_ENDPOINT:?APP_SYNC_ENDPOINT not set}"
API_KEY="${APP_SYNC_API_KEY:?APP_SYNC_API_KEY not set}"

JSON_FILE="${1:-}"
if [ -z "$JSON_FILE" ]; then
  echo "Usage: $0 <event-json-file>"
  exit 1
fi

INPUT=$(python3 -c "
import json, sys
with open('$JSON_FILE') as f:
    data = json.load(f)
# Remove read-only / auto-managed fields
for k in ['id', 'createdAt', 'updatedAt', '_version', '_deleted', '_lastChangedAt', '_note']:
    data.pop(k, None)
# Remove null fields (optional)
data = {k: v for k, v in data.items() if v is not None}
print(json.dumps(data))
")

QUERY='mutation CreateEvent($input: CreateEventInput!) { createEvent(input: $input) { id type date title venueName published } }'
PAYLOAD=$(python3 -c "
import json, sys
q = '$QUERY'
inp = $INPUT
print(json.dumps({'query': q, 'variables': {'input': inp}}))
")

echo "Creating event from $JSON_FILE ..."
RESULT=$(curl -s -X POST "$ENDPOINT" \
  -H "Content-Type: application/json" \
  -H "x-api-key: $API_KEY" \
  -d "$PAYLOAD")

echo "$RESULT" | python3 -m json.tool
echo ""
echo "Done. Run 'bash deploy.sh' to rebuild the site."