{"openapi":"3.0.3","info":{"title":"Anna-Daan API","version":"1.0.0","description":"OpenAPI specification for the Anna-Daan food rescue platform.\nThis spec reflects the implemented legacy backend endpoints in `Backend/server.js`,\nwhich currently power the working system.\n"},"servers":[{"url":"http://localhost:5000","description":"Local development server"}],"tags":[{"name":"Health"},{"name":"Auth"},{"name":"Donor"},{"name":"NGO"},{"name":"Volunteer"},{"name":"Admin"},{"name":"Certificates"}],"paths":{"/api/health":{"get":{"tags":["Health"],"summary":"Check backend health","responses":{"200":{"description":"API is reachable","content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string","example":"ok"}}}}}}}}},"/api/auth/register":{"post":{"tags":["Auth"],"summary":"Register user and send OTP","requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RegisterRequest"}}}},"responses":{"200":{"description":"OTP sent"},"400":{"description":"Validation failed"},"409":{"description":"Email or phone already registered"}}}},"/api/auth/register/{role}":{"post":{"tags":["Auth"],"summary":"Register user with role in path","parameters":[{"in":"path","name":"role","required":true,"schema":{"type":"string","enum":["donor","ngo","volunteer"]}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/RegisterRequest"}}}},"responses":{"200":{"description":"OTP sent"}}}},"/api/auth/verify-otp":{"post":{"tags":["Auth"],"summary":"Verify registration OTP","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["email","otp"],"properties":{"email":{"type":"string"},"otp":{"type":"string"}}}}}},"responses":{"200":{"description":"Account verified"},"400":{"description":"Invalid or expired OTP"},"404":{"description":"Pending registration not found"}}}},"/api/auth/login":{"post":{"tags":["Auth"],"summary":"Login with email or phone and role","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["identifier","role"],"properties":{"identifier":{"type":"string"},"password":{"type":"string"},"role":{"type":"string","enum":["donor","ngo","volunteer"]}}}}}},"responses":{"200":{"description":"Login successful","content":{"application/json":{"schema":{"type":"object","properties":{"success":{"type":"boolean"},"message":{"type":"string"},"user":{"$ref":"#/components/schemas/LegacyUser"}}}}}},"401":{"description":"Invalid credentials"}}}},"/api/donor/profile/{donorId}":{"get":{"tags":["Donor"],"summary":"Get donor profile","parameters":[{"$ref":"#/components/parameters/DonorId"}],"responses":{"200":{"description":"Donor profile fetched"}}},"put":{"tags":["Donor"],"summary":"Update donor profile","parameters":[{"$ref":"#/components/parameters/DonorId"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object"}}}},"responses":{"200":{"description":"Donor profile updated"}}}},"/api/donor/donate":{"post":{"tags":["Donor"],"summary":"Create a new donation","requestBody":{"required":true,"content":{"multipart/form-data":{"schema":{"type":"object","required":["donorId"],"properties":{"donorId":{"type":"string"},"item":{"type":"string"},"qty":{"type":"string"},"preparedTime":{"type":"string","example":"14:30"},"latitude":{"type":"string"},"longitude":{"type":"string"},"address":{"type":"string"},"itemDetails":{"type":"string","description":"JSON stringified item detail array"},"image":{"type":"string","format":"binary"}}}}}},"responses":{"201":{"description":"Donation created"},"200":{"description":"Duplicate donation ignored"}}}},"/api/donor/donations/{donorId}":{"get":{"tags":["Donor"],"summary":"Get donor donation history","parameters":[{"$ref":"#/components/parameters/DonorId"},{"in":"query","name":"status","schema":{"type":"string"}},{"in":"query","name":"limit","schema":{"type":"integer"}}],"responses":{"200":{"description":"Donation history fetched"}}}},"/api/donor/donation/{donationId}":{"get":{"tags":["Donor"],"summary":"Get one donation by ID","parameters":[{"$ref":"#/components/parameters/DonationId"}],"responses":{"200":{"description":"Donation fetched"}}},"put":{"tags":["Donor"],"summary":"Update donation status","parameters":[{"$ref":"#/components/parameters/DonationId"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"status":{"type":"string"}}}}}},"responses":{"200":{"description":"Donation updated"}}}},"/api/donor/stats/{donorId}":{"get":{"tags":["Donor"],"summary":"Get donor impact statistics","parameters":[{"$ref":"#/components/parameters/DonorId"}],"responses":{"200":{"description":"Statistics fetched"}}}},"/api/donor/verify-otp":{"post":{"tags":["Donor"],"summary":"Verify pickup OTP","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["donationId","otp"],"properties":{"donationId":{"type":"string"},"otp":{"type":"integer"}}}}}},"responses":{"200":{"description":"Pickup verified"}}}},"/api/ngo/claim-donation":{"post":{"tags":["NGO"],"summary":"Claim an active donation","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["donationId","ngoId"],"properties":{"donationId":{"type":"string"},"ngoId":{"type":"string"}}}}}},"responses":{"200":{"description":"Donation claimed"}}}},"/api/ngo/active-donations/{ngoId}":{"get":{"tags":["NGO"],"summary":"Get nearby active donations","parameters":[{"$ref":"#/components/parameters/NgoId"},{"in":"query","name":"radius","schema":{"type":"number","default":20}}],"responses":{"200":{"description":"Nearby donations fetched"}}}},"/api/ngo/claimed-donations/{ngoId}":{"get":{"tags":["NGO"],"summary":"Get NGO claimed donations","parameters":[{"$ref":"#/components/parameters/NgoId"}],"responses":{"200":{"description":"Claimed donations fetched"}}}},"/api/ngo/stats/{ngoId}":{"get":{"tags":["NGO"],"summary":"Get NGO statistics","parameters":[{"$ref":"#/components/parameters/NgoId"}],"responses":{"200":{"description":"NGO stats fetched"}}}},"/api/ngo/profile/{ngoId}":{"get":{"tags":["NGO"],"summary":"Get NGO profile","parameters":[{"$ref":"#/components/parameters/NgoId"}],"responses":{"200":{"description":"NGO profile fetched"}}}},"/api/ngo/complete-delivery":{"post":{"tags":["NGO"],"summary":"Mark NGO delivery as complete","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["donationId","ngoId"],"properties":{"donationId":{"type":"string"},"ngoId":{"type":"string"},"comment":{"type":"string"}}}}}},"responses":{"200":{"description":"Delivery completed"}}}},"/api/volunteer/open-rescues/{volunteerId}":{"get":{"tags":["Volunteer"],"summary":"Get open rescue tasks for volunteer","parameters":[{"$ref":"#/components/parameters/VolunteerId"}],"responses":{"200":{"description":"Open rescues fetched"}}}},"/api/volunteer/active-mission/{volunteerId}":{"get":{"tags":["Volunteer"],"summary":"Get volunteer active mission","parameters":[{"$ref":"#/components/parameters/VolunteerId"}],"responses":{"200":{"description":"Active mission fetched"}}}},"/api/volunteer/accept-rescue":{"post":{"tags":["Volunteer"],"summary":"Accept open rescue","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["donationId","volunteerId"],"properties":{"donationId":{"type":"string"},"volunteerId":{"type":"string"}}}}}},"responses":{"200":{"description":"Rescue accepted"}}}},"/api/volunteer/complete-delivery":{"post":{"tags":["Volunteer"],"summary":"Complete volunteer delivery with proof image","requestBody":{"required":true,"content":{"multipart/form-data":{"schema":{"type":"object","required":["donationId","volunteerId","proof_image"],"properties":{"donationId":{"type":"string"},"volunteerId":{"type":"string"},"comment":{"type":"string"},"lat":{"type":"string"},"lng":{"type":"string"},"proof_image":{"type":"string","format":"binary"}}}}}},"responses":{"200":{"description":"Delivery completed"}}}},"/api/admin/login":{"post":{"tags":["Admin"],"summary":"Admin login","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["email","password"],"properties":{"email":{"type":"string"},"password":{"type":"string"}}}}}},"responses":{"200":{"description":"Admin login successful"}}}},"/api/admin/logout":{"post":{"tags":["Admin"],"summary":"Admin logout","responses":{"200":{"description":"Admin logout successful"}}}},"/api/admin/health":{"get":{"tags":["Admin"],"summary":"Admin API health","responses":{"200":{"description":"Admin API healthy"}}}},"/api/admin/system-status":{"get":{"tags":["Admin"],"summary":"Get system summary","responses":{"200":{"description":"System status fetched"}}}},"/api/admin/users":{"get":{"tags":["Admin"],"summary":"Get users","parameters":[{"in":"query","name":"role","schema":{"type":"string"}},{"in":"query","name":"search","schema":{"type":"string"}}],"responses":{"200":{"description":"Users fetched"}}}},"/api/admin/users/{id}":{"get":{"tags":["Admin"],"summary":"Get user by ID","parameters":[{"$ref":"#/components/parameters/UserId"}],"responses":{"200":{"description":"User fetched"}}},"put":{"tags":["Admin"],"summary":"Update user","parameters":[{"$ref":"#/components/parameters/UserId"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object"}}}},"responses":{"200":{"description":"User updated"}}},"delete":{"tags":["Admin"],"summary":"Delete user","parameters":[{"$ref":"#/components/parameters/UserId"}],"responses":{"200":{"description":"User deleted"}}}},"/api/admin/users/{id}/verify":{"put":{"tags":["Admin"],"summary":"Verify or unverify user","parameters":[{"$ref":"#/components/parameters/UserId"}],"requestBody":{"required":false,"content":{"application/json":{"schema":{"type":"object","properties":{"verified":{"type":"boolean"}}}}}},"responses":{"200":{"description":"Verification updated"}}}},"/api/admin/users/{id}/toggle-status":{"put":{"tags":["Admin"],"summary":"Toggle user verified status","parameters":[{"$ref":"#/components/parameters/UserId"}],"responses":{"200":{"description":"User status toggled"}}}},"/api/admin/users/stats/overview":{"get":{"tags":["Admin"],"summary":"Get user overview statistics","responses":{"200":{"description":"User stats fetched"}}}},"/api/admin/donations":{"get":{"tags":["Admin"],"summary":"Get donations","parameters":[{"in":"query","name":"status","schema":{"type":"string"}}],"responses":{"200":{"description":"Donations fetched"}}}},"/api/admin/donations/{id}":{"get":{"tags":["Admin"],"summary":"Get donation by ID","parameters":[{"$ref":"#/components/parameters/DonationRecordId"}],"responses":{"200":{"description":"Donation fetched"}}},"put":{"tags":["Admin"],"summary":"Update donation","parameters":[{"$ref":"#/components/parameters/DonationRecordId"}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object"}}}},"responses":{"200":{"description":"Donation updated"}}},"delete":{"tags":["Admin"],"summary":"Delete donation","parameters":[{"$ref":"#/components/parameters/DonationRecordId"}],"responses":{"200":{"description":"Donation deleted"}}}},"/api/admin/donations/stats/overview":{"get":{"tags":["Admin"],"summary":"Get donation statistics","responses":{"200":{"description":"Donation stats fetched"}}}},"/api/admin/transactions":{"get":{"tags":["Admin"],"summary":"Get transactions","responses":{"200":{"description":"Transactions fetched"}}}},"/api/admin/transactions/{id}":{"get":{"tags":["Admin"],"summary":"Get transaction by ID","parameters":[{"$ref":"#/components/parameters/TransactionId"}],"responses":{"200":{"description":"Transaction fetched"}}}},"/api/admin/transactions/stats/overview":{"get":{"tags":["Admin"],"summary":"Get transaction statistics","responses":{"200":{"description":"Transaction stats fetched"}}}},"/api/admin/pending-registrations":{"get":{"tags":["Admin"],"summary":"Get valid pending registrations","responses":{"200":{"description":"Pending registrations fetched"}}}},"/api/admin/pending-registrations/approve":{"post":{"tags":["Admin"],"summary":"Approve pending registration","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["registrationId"],"properties":{"registrationId":{"type":"string"}}}}}},"responses":{"200":{"description":"Registration approved"}}}},"/api/admin/pending-registrations/{id}":{"delete":{"tags":["Admin"],"summary":"Reject pending registration","parameters":[{"$ref":"#/components/parameters/PendingId"}],"responses":{"200":{"description":"Registration rejected"}}}},"/api/admin/pending-registrations/clear-all":{"post":{"tags":["Admin"],"summary":"Clear expired pending registrations","responses":{"200":{"description":"Expired pending registrations cleared"}}}},"/api/admin/clear-pending":{"post":{"tags":["Admin"],"summary":"Debug endpoint to clear pending registrations","requestBody":{"required":false,"content":{"application/json":{"schema":{"type":"object","properties":{"email":{"type":"string"}}}}}},"responses":{"200":{"description":"Pending registrations cleared"}}}},"/api/admin/test-whatsapp":{"post":{"tags":["Admin"],"summary":"Send test WhatsApp message","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["phone"],"properties":{"phone":{"type":"string"},"message":{"type":"string"},"mediaUrl":{"type":"string"}}}}}},"responses":{"200":{"description":"Test message sent"}}}},"/api/admin/whatsapp-health":{"get":{"tags":["Admin"],"summary":"Get WhatsApp configuration health","responses":{"200":{"description":"WhatsApp health fetched"}}}},"/api/admin/certificates/eligibility/{userId}":{"get":{"tags":["Certificates"],"summary":"Get certificate eligibility for user","parameters":[{"$ref":"#/components/parameters/UserId"}],"responses":{"200":{"description":"Eligibility fetched"}}}},"/api/admin/certificates/generate":{"post":{"tags":["Certificates"],"summary":"Generate certificate","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["userId"],"properties":{"userId":{"type":"string"},"type":{"type":"string","enum":["BRONZE","SILVER","GOLD","DIAMOND"]},"title":{"type":"string"},"description":{"type":"string"},"recipientName":{"type":"string"},"customDescription":{"type":"string"}}}}}},"responses":{"200":{"description":"Certificate generated"}}}},"/api/admin/certificates":{"get":{"tags":["Certificates"],"summary":"Get all certificates","responses":{"200":{"description":"Certificates fetched"}}}},"/api/admin/certificates/{id}":{"get":{"tags":["Certificates"],"summary":"Get certificate by ID","parameters":[{"$ref":"#/components/parameters/CertificateId"}],"responses":{"200":{"description":"Certificate fetched"}}},"delete":{"tags":["Certificates"],"summary":"Delete certificate","parameters":[{"$ref":"#/components/parameters/CertificateId"}],"responses":{"200":{"description":"Certificate deleted"}}}},"/api/admin/certificates/stats/overview":{"get":{"tags":["Certificates"],"summary":"Get certificate statistics","responses":{"200":{"description":"Certificate stats fetched"}}}},"/api/admin/certificates/send-email":{"post":{"tags":["Certificates"],"summary":"Send certificate email with PDF attachment","requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","properties":{"id":{"type":"string"},"certificateId":{"type":"string"}}}}}},"responses":{"200":{"description":"Certificate email sent"}}}}},"components":{"parameters":{"UserId":{"in":"path","name":"id","required":true,"schema":{"type":"string"}},"DonorId":{"in":"path","name":"donorId","required":true,"schema":{"type":"string"}},"NgoId":{"in":"path","name":"ngoId","required":true,"schema":{"type":"string"}},"VolunteerId":{"in":"path","name":"volunteerId","required":true,"schema":{"type":"string"}},"DonationId":{"in":"path","name":"donationId","required":true,"schema":{"type":"string"}},"DonationRecordId":{"in":"path","name":"id","required":true,"schema":{"type":"string"}},"TransactionId":{"in":"path","name":"id","required":true,"schema":{"type":"string"}},"PendingId":{"in":"path","name":"id","required":true,"schema":{"type":"string"}},"CertificateId":{"in":"path","name":"id","required":true,"schema":{"type":"string"}}},"schemas":{"RegisterRequest":{"type":"object","required":["name","phone","email","role"],"properties":{"name":{"type":"string"},"phone":{"type":"string"},"email":{"type":"string"},"password":{"type":"string"},"role":{"type":"string","enum":["donor","ngo","volunteer"]},"ngoName":{"type":"string"},"registrationNumber":{"type":"string"},"maxPeopleServed":{"type":"integer"},"location":{"$ref":"#/components/schemas/Location"}}},"Location":{"type":"object","properties":{"lat":{"type":"number"},"lng":{"type":"number"},"address":{"type":"string"}}},"LegacyUser":{"type":"object","properties":{"_id":{"type":"string"},"name":{"type":"string"},"phone":{"type":"string"},"email":{"type":"string"},"role":{"type":"string"},"verified":{"type":"boolean"},"location":{"$ref":"#/components/schemas/Location"},"green_credits":{"type":"integer"},"ngoName":{"type":"string","nullable":true},"registrationNumber":{"type":"string","nullable":true},"maxPeopleServed":{"type":"integer","nullable":true}}},"Donation":{"type":"object","properties":{"_id":{"type":"string"},"donor_id":{"type":"string"},"food_items":{"type":"string"},"quantity_kg":{"type":"number"},"cooked_time":{"type":"string","format":"date-time"},"expiry_time":{"type":"string","format":"date-time"},"status":{"type":"string"},"location":{"$ref":"#/components/schemas/Location"},"image_url":{"type":"string","nullable":true}}}}}}