Skip to main content
This page documents two related endpoints for listing churches based on different user contexts.

Get Pastor Churches

Retrieve all churches where the authenticated user is the pastor.

Authentication

This endpoint requires:
  • Valid JWT token in the Authorization header
  • User role must be pastor

Endpoint

GET /api/church/getchurches/:pastorId

Path Parameters

pastorId
string
required
The MongoDB ObjectId of the pastor. This should match the authenticated user’s profile ID.

Response

success
boolean
Indicates whether the operation was successful.
message
string
A descriptive message including the count of churches found.
data
array
Array of church objects where the user is the pastor.
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
Populated pastor profile object (excludes sensitive auth details).
data[].members
array
Array of populated member profile objects (excludes sensitive auth details).

Example Request

curl -X GET https://api.example.com/api/church/getchurches/507f1f77bcf86cd799439011 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Example Response

Success (200 OK)

{
  "success": true,
  "message": "You have 2 church(es)",
  "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",
        "phoneNumber": "+1-555-987-6543"
      },
      "members": [
        {
          "name": "John Smith",
          "phoneNumber": "+1-555-987-6543"
        },
        {
          "name": "Jane Doe",
          "phoneNumber": "+1-555-111-2222"
        }
      ]
    },
    {
      "_id": "507f191e810c19729de860eb",
      "name": "Faith Chapel",
      "address": "456 Oak Avenue, Springfield, IL 62702",
      "supportcontact": {
        "phone": "+1-555-765-4321",
        "email": "[email protected]"
      },
      "pastor": {
        "name": "John Smith",
        "phoneNumber": "+1-555-987-6543"
      },
      "members": [
        {
          "name": "John Smith",
          "phoneNumber": "+1-555-987-6543"
        }
      ]
    }
  ]
}

No Churches Found (404 Not Found)

{
  "success": false,
  "message": "Unable to fetch churches",
  "data": "You do not have any churches"
}

Unauthorized - Not a Pastor (403 Forbidden)

{
  "success": false,
  "message": "Access Denied",
  "data": "The role 'member' is not allowed for this route"
}

Get User Churches

Retrieve all churches where the authenticated user is a member.

Authentication

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

Endpoint

GET /api/church/getuserchurches/:id

Path Parameters

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

Response

success
boolean
Indicates whether the operation was successful.
message
string
A descriptive message including the count of churches found.
data
array
Array of church objects where the user is a member.
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
Populated pastor profile object with basic information (excludes auth details and sensitive fields).

Example Request

curl -X GET https://api.example.com/api/church/getuserchurches/507f1f77bcf86cd799439011 \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Example Response

Success (200 OK)

{
  "success": true,
  "message": "You are in 3 church(es)",
  "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",
        "phoneNumber": "+1-555-987-6543"
      }
    },
    {
      "_id": "507f191e810c19729de860eb",
      "name": "Faith Chapel",
      "address": "456 Oak Avenue, Springfield, IL 62702",
      "supportcontact": {
        "phone": "+1-555-765-4321",
        "email": "[email protected]"
      },
      "pastor": {
        "name": "Michael Johnson",
        "phoneNumber": "+1-555-333-4444"
      }
    },
    {
      "_id": "507f191e810c19729de860ec",
      "name": "Hope Church",
      "address": "789 Elm Street, Springfield, IL 62703",
      "supportcontact": {
        "phone": "+1-555-999-8888",
        "email": "[email protected]",
        "website": "https://hopechurch.org"
      },
      "pastor": {
        "name": "Sarah Williams",
        "phoneNumber": "+1-555-777-6666"
      }
    }
  ]
}

No Churches Found (404 Not Found)

{
  "success": false,
  "message": "Unable to fetch churches",
  "data": "You are not a member of any church yet"
}

Server Error (500 Internal Server Error)

{
  "success": false,
  "message": "Unable to fetch churches",
  "data": "Error message details"
}

Notes

Pastor Churches Endpoint

  • Only accessible by users with pastor role
  • Returns complete church information including all members
  • Useful for pastors to manage their churches
  • Member list is fully populated with profile details

User Churches Endpoint

  • Accessible by any authenticated user (pastor or member)
  • Returns churches where the user is a member (including as pastor)
  • Member list is excluded from the response for privacy
  • Only pastor information is populated
  • Both endpoints return an empty result with 404 if no churches are found

Build docs developers (and LLMs) love