Skip to main content
PATCH
/
api
/
church
/
exitchurch
/
:id
Exit Church
curl --request PATCH \
  --url https://api.example.com/api/church/exitchurch/:id \
  --header 'Content-Type: application/json' \
  --data '
{
  "userId": "<string>"
}
'
{
  "success": true,
  "message": "<string>",
  "data": {
    "data._id": "<string>",
    "data.name": "<string>",
    "data.address": "<string>",
    "data.supportcontact": {},
    "data.pastor": {}
  }
}

Authentication

This endpoint requires:
  • Valid JWT token in the Authorization header
  • Any authenticated user role (pastor or member)

Endpoint

PATCH /api/church/exitchurch/:id

Path Parameters

id
string
required
The MongoDB ObjectId of the church to exit.

Request Body

userId
string
required
The MongoDB ObjectId of the user profile exiting the church. This should match the authenticated user’s profile ID.

Response

success
boolean
Indicates whether the exit operation was successful.
message
string
A descriptive message about the operation result.
data
object
The church object (excludes member list for privacy).
data._id
string
The unique MongoDB ObjectId of the church.
data.name
string
The name of the church.
data.address
string
The physical address of the church.
data.supportcontact
object
Contact information object containing phone, email, and optional website.
data.pastor
object
Pastor information object with name field.

Example Request

curl -X PATCH https://api.example.com/api/church/exitchurch/507f191e810c19729de860ea \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "507f1f77bcf86cd799439011"
  }'

Example Response

Success (200 OK)

{
  "success": true,
  "message": "You have successfully exited Grace Community Church",
  "data": {
    "_id": "507f191e810c19729de860ea",
    "name": "Grace Community Church",
    "address": "123 Main Street, Springfield, IL 62701",
    "supportcontact": {
      "phone": "+1-555-123-4567",
      "email": "[email protected]",
      "website": "https://gracechurch.org"
    },
    "pastor": {
      "name": "John Smith"
    }
  }
}

Not a Member (400 Bad Request)

{
  "success": false,
  "message": "Unable to exit church",
  "data": "You are not a member of this church"
}

Church Not Found (404 Not Found)

{
  "success": false,
  "message": "Unable to exit church",
  "data": "Church with this Id does not exist"
}

Server Error (500 Internal Server Error)

{
  "success": false,
  "message": "Unable to exit church",
  "data": "Error message details"
}

Notes

  • Users can only exit churches they are currently members of
  • The endpoint verifies membership before attempting to remove the user
  • If not a member, the response returns success: false with a 400 status code
  • The user is removed from the church’s members array
  • Both pastors and regular members can exit churches using this endpoint
  • Pastors can exit their own churches (though this may leave the church without a pastor)

Build docs developers (and LLMs) love