Skip to content

Planetxlive/planetx-backend

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Planet-X-Backend

API Documentation

Authentication API

This API provides endpoints for OTP-based user authentication.


Base URL

http://localhost:4000 for running locally

http://api.planetx-live.com for aws url


Endpoints


1. Send OTP

Description

This endpoint generates and sends an OTP to the user's mobile number for authentication. The OTP is valid for 5 minutes.

Method

POST

Endpoint

api/auth/send-otp

Headers

  • Content-Type: application/json

Request Body

{
  "mobile": "+91<10-digit-mobile-number>"
}
  • Replace <10-digit-mobile-number> with the user’s mobile number prefixed with +91.

Sample Request

{
  "mobile": "+919519896860"
}

Response

Success:

{
  "message": "OTP sent successfully"
}

Error Responses:

  • 400 Bad Request: Missing or invalid mobile field.
    Example:
    {
      "message": "Mobile number is required"
    }
  • 500 Internal Server Error: Failure in sending OTP.
    Example:
    {
      "message": "Error sending OTP",
      "error": "<error-details>"
    }

2. Verify OTP

Description

This endpoint verifies the OTP sent to the user's mobile number. If successful, it generates a JWT token that can be used for subsequent authentication.

Method

POST

Endpoint

api/auth/verify-otp

Headers

  • Content-Type: application/json

Request Body

{
  "mobile": "+91<10-digit-mobile-number>",
  "otp": "<4-digit-otp>"
}
  • Replace <10-digit-mobile-number> with the user’s mobile number prefixed with +91.
  • Replace <4-digit-otp> with the OTP received by the user.

Sample Request

{
  "mobile": "+919580884280",
  "otp": "3560"
}

Response

Success:

{
  "message": "Login successful",
  "token": "<jwt-token>"
}
  • Replace <jwt-token> with the actual JWT token generated by the backend.

Error Responses:

  • 400 Bad Request: Missing mobile or otp field.
    Example:
    {
      "message": "Mobile number and OTP are required"
    }
  • 404 Not Found: Mobile number not found in the system.
    Example:
    {
      "message": "User not found"
    }
  • 400 Bad Request: OTP expired.
    Example:
    {
      "message": "OTP expired"
    }
  • 400 Bad Request: Invalid OTP.
    Example:
    {
      "message": "Invalid OTP"
    }

Usage Notes

  1. Mobile Number Format
    Ensure the mobile number is prefixed with the country code (+91 for India).

  2. OTP Expiry
    The OTP is valid for 5 minutes. Ensure the user submits the OTP before it expires.

  3. Token Usage
    The token provided in the response should be included in the Authorization header for subsequent authenticated requests:

    Authorization: Bearer <jwt-token>
    

3. Property Addition API Documentation

Endpoint

POST api/properties/add

Description

This API is used to add a new property to the system. It accepts the details of the property, including its type, location, furnishings, amenities, and multimedia content (images and videos).

Request Body

{
  "propertyType": "For Sale",
  "category": "Residential",
  "location": {
    "city": "Mumbai",
    "state": "Maharashtra",
    "locality": "Andheri",
    "subLocality": "Lokhandwala",
    "apartment": "ABC Residency",
    "houseNumber": "Flat 302"
  },
  "about": {
    "bedrooms": 3,
    "bathrooms": 2,
    "balconies": 2
  },
  "propertyArea": {
    "carpetArea": 1200,
    "builtUpArea": 1400
  },
  "otherRooms": {
    "poojaRoom": true,
    "guestRoom": true,
    "servantRoom": false,
    "studyRoom": true
  },
  "furnishingStatus": "Fully Furnished",
  "furnishingDetails": {
    "fans": 5,
    "lights": 10,
    "tv": 2,
    "beds": 3,
    "ac": 2,
    "wardrobes": 3,
    "exhaustFans": 2,
    "curtains": 6,
    "floorLamps": 2,
    "diningTable": true,
    "sofa": true,
    "stove": true,
    "kitchenCabinets": true,
    "chimney": true,
    "coffeeTable": true,
    "refrigerator": true,
    "microwave": true,
    "dishwasher": false,
    "waterPurifier": true,
    "washingMachine": true
  },
  "totalFloors": 10,
  "propertyOnFloor": 3,
  "flatNumber": "302",
  "parking": {
    "covered": 1,
    "open": 1
  },
  "availabilityStatus": "Ready to Move",
  "availableFrom": "2024-01-01",
  "ageOfProperty": 5,
  "description": "Beautifully furnished 3BHK apartment in a prime location with all modern amenities."
}

Response

Success Response (HTTP Status 200)
{
  "message": "Property added successfully",
  "property": {
    "user": "67555adb6635b9a4fa1b2c7c",
    "propertyType": "For Sale",
    "category": "Residential",
    "location": {
      "city": "Mumbai",
      "state": "Maharashtra",
      "locality": "Andheri",
      "subLocality": "Lokhandwala",
      "apartment": "ABC Residency",
      "houseNumber": "Flat 302"
    },
    "about": {
      "bedrooms": 3,
      "bathrooms": 2,
      "balconies": 2
    },
    "propertyArea": {
      "carpetArea": 1200,
      "builtUpArea": 1400
    },
    "otherRooms": {
      "poojaRoom": true,
      "guestRoom": true,
      "servantRoom": false,
      "studyRoom": true
    },
    "furnishingStatus": "Fully Furnished",
    "furnishingDetails": {
      "fans": 5,
      "lights": 10,
      "tv": 2,
      "beds": 3,
      "ac": 2,
      "wardrobes": 3,
      "exhaustFans": 2,
      "curtains": 6,
      "floorLamps": 2,
      "diningTable": true,
      "sofa": true,
      "stove": true,
      "kitchenCabinets": true,
      "chimney": true,
      "coffeeTable": true,
      "refrigerator": true,
      "microwave": true,
      "dishwasher": false,
      "waterPurifier": true,
      "washingMachine": true
    },
    "totalFloors": 10,
    "propertyOnFloor": 3,
    "flatNumber": "302",
    "parking": {
      "covered": 1,
      "open": 1
    },
    "availabilityStatus": "Ready to Move",
    "availableFrom": "2024-01-01T00:00:00.000Z",
    "ageOfProperty": 5,
    "description": "Beautifully furnished 3BHK apartment in a prime location with all modern amenities.",
    "images": [
      {
        "name": "house.jpg",
        "url": "https://res.cloudinary.com/dtfhslkcx/image/upload/v1733650279/properties/images/hbytqrmeyrzghrqnixij.jpg",
        "_id": "675567683c5a4f0318851083"
      }
    ],
    "video": "https://res.cloudinary.com/dtfhslkcx/video/upload/v1733650280/properties/videos/gaudnkxkie5ajhdvhre2.mp4",
    "_id": "675567683c5a4f0318851082",
    "__v": 0
  }
}
Error Response (HTTP Status 400)
{
  "error": "Validation failed",
  "message": "Some required fields are missing or incorrect."
}

Notes

  • availableFrom should be in the format YYYY-MM-DD or ISO 8601.
  • Ensure that the property data such as area, rooms, and furnishings are accurately provided to avoid validation errors.

Here is the updated documentation with the required changes:


4. For Editing Property route

Endpoint: PATCH api/properties/:propertyId

This endpoint is used to update an existing property in the database. You can update property details such as images, video, description, and furnishing details.

Request Parameters:

  • propertyId (required): The unique ID of the property to be updated.
  • imageId (optional): The unique ID of the image to be updated.

Request Body:

  • propertyData (optional): Updated property data. The data should be sent as a stringified JSON object containing the following fields:

    • location: The address details of the property.
      • city: The city where the property is located.
      • state: The state of the property.
      • locality: The locality within the city.
      • subLocality: The sub-locality within the locality.
      • apartment: The apartment name/building name.
      • houseNumber: The house number or flat number.
    • about: The number of rooms and facilities in the property.
      • bedrooms: The number of bedrooms.
      • bathrooms: The number of bathrooms.
      • balconies: The number of balconies.
    • propertyArea: The area of the property.
      • carpetArea: The carpet area of the property.
      • builtUpArea: The built-up area of the property.
    • otherRooms: The presence of other rooms in the property.
      • poojaRoom: Boolean indicating the presence of a pooja room.
      • guestRoom: Boolean indicating the presence of a guest room.
      • servantRoom: Boolean indicating the presence of a servant room.
      • studyRoom: Boolean indicating the presence of a study room.
    • furnishingDetails: The details of the furnishings in the property.
      • fans, lights, tv, beds, ac, wardrobes, exhaustFans, curtains, floorLamps, diningTable, sofa, stove, kitchenCabinets, chimney, coffeeTable, refrigerator, microwave, dishwasher, waterPurifier, washingMachine: The number or presence of each of these furnishing items.
    • parking: The parking details.
      • covered: The number of covered parking spaces.
      • open: The number of open parking spaces.
    • propertyType: The type of property (e.g., "For Sale").
    • category: The category of the property (e.g., "Residential").
    • furnishingStatus: The status of furnishing (e.g., "Half Furnished").
    • totalFloors: The total number of floors in the building.
    • propertyOnFloor: The floor on which the property is located.
    • flatNumber: The flat number of the property.
    • availabilityStatus: The availability status (e.g., "Ready to Move").
    • availableFrom: The date when the property is available from.
    • ageOfProperty: The age of the property.
    • description: A description of the property.
  • images (optional): Array of images to upload for the property.

    • imageId (optional): The ID of the image to be updated.
    • If the imageId is provided, the specific image will be updated with the new one.
    • If no imageId is provided, new images will be added.
  • video (optional): The video to upload for the property (optional).

Example Request Body:

{
  "propertyData": {
    "location": {
      "city": "Mumbai",
      "state": "Maharashtra",
      "locality": "Andheri",
      "subLocality": "Lokhandwala",
      "apartment": "ABC Residency",
      "houseNumber": "Flat 302"
    },
    "about": {
      "bedrooms": 3,
      "bathrooms": 2,
      "balconies": 2
    },
    "propertyArea": {
      "carpetArea": 1200,
      "builtUpArea": 1400
    },
    "otherRooms": {
      "poojaRoom": true,
      "guestRoom": true,
      "servantRoom": false,
      "studyRoom": true
    },
    "furnishingDetails": {
      "fans": 5,
      "lights": 10,
      "tv": 2,
      "beds": 3,
      "ac": 2,
      "wardrobes": 3,
      "exhaustFans": 2,
      "curtains": 6,
      "floorLamps": 2,
      "diningTable": true,
      "sofa": true,
      "stove": true,
      "kitchenCabinets": true,
      "chimney": true,
      "coffeeTable": true,
      "refrigerator": true,
      "microwave": true,
      "dishwasher": false,
      "waterPurifier": true,
      "washingMachine": true
    },
    "parking": {
      "covered": 1,
      "open": 1
    },
    "propertyType": "For Sale",
    "category": "Residential",
    "furnishingStatus": "Half Furnished",
    "totalFloors": 10,
    "propertyOnFloor": 3,
    "flatNumber": "302",
    "availabilityStatus": "Ready to Move",
    "availableFrom": "2024-01-01T00:00:00.000Z",
    "ageOfProperty": 5,
    "description": "Updated property description"
  },
  "images": [
    {
      "imageId": "6756b7707d8926a3fc06f3f6"
    }
  ]
}

Response:

Success Response:

  • Status: 200 OK
  • Response Body:
    {
      "message": "Property updated successfully",
      "property": {
        "location": {
          "city": "Mumbai",
          "state": "Maharashtra",
          "locality": "Andheri",
          "subLocality": "Lokhandwala",
          "apartment": "ABC Residency",
          "houseNumber": "Flat 302"
        },
        "about": {
          "bedrooms": 3,
          "bathrooms": 2,
          "balconies": 2
        },
        "propertyArea": {
          "carpetArea": 1200,
          "builtUpArea": 1400
        },
        "otherRooms": {
          "poojaRoom": true,
          "guestRoom": true,
          "servantRoom": false,
          "studyRoom": true
        },
        "furnishingDetails": {
          "fans": 5,
          "lights": 10,
          "tv": 2,
          "beds": 3,
          "ac": 2,
          "wardrobes": 3,
          "exhaustFans": 2,
          "curtains": 6,
          "floorLamps": 2,
          "diningTable": true,
          "sofa": true,
          "stove": true,
          "kitchenCabinets": true,
          "chimney": true,
          "coffeeTable": true,
          "refrigerator": true,
          "microwave": true,
          "dishwasher": false,
          "waterPurifier": true,
          "washingMachine": true
        },
        "parking": {
          "covered": 1,
          "open": 1
        },
        "_id": "675566483c5a4f031885107d",
        "user": "67555adb6635b9a4fa1b2c7c",
        "propertyType": "For Sale",
        "category": "Residential",
        "furnishingStatus": "Half Furnished",
        "totalFloors": 10,
        "propertyOnFloor": 3,
        "flatNumber": "302",
        "availabilityStatus": "Ready to Move",
        "availableFrom": "2024-01-01T00:00:00.000Z",
        "ageOfProperty": 5,
        "description": "Updated property description",
        "images": [
          {
            "name": "updatedHouse.jpg",
            "url": "https://res.cloudinary.com/dtfhslkcx/image/upload/v1733736305/properties/images/vnnp7r24oyntll4ld9cy.jpg",
            "_id": "6756b7707d8926a3fc06f3f6"
          },
          {
            "name": "updatedHouse.jpg",
            "url": "https://res.cloudinary.com/dtfhslkcx/image/upload/v1733814519/properties/images/sx7jaarn8v3goagadudm.jpg",
            "_id": "6756b7297d8926a3fc06f3ef"
          }
        ],
        "video": null,
        "__v": 0
      }
    }

Error Response:

  • Status: 404 Not Found

  • Response Body:

    {
      "message": "Property not found"
    }
  • Status

: 400 Bad Request

  • Response Body:
    {
      "message": "Property ID is required"
    }

5. Endpoint: Get All Properties of Users added to their account

Route: GET api/properties/alluser-properties

Description

This endpoint fetches the active properties of a user based on their mobile number.

Request

  • Method: GET
  • Body:
    • mobile (string, required): The mobile number of the user whose active properties are to be fetched.

Response

  • Status Code: 200 OK

    • Body:
      {
        "message": "properties fetched successfully.",
        "properties": [
          /* Array of user active properties */
        ]
      }
  • Status Code: 400 Bad Request

    • Body:
      {
        "error": "Mobile number is required."
      }
  • Status Code: 404 Not Found

    • Body:
      {
        "error": "User not found."
      }
  • Status Code: 500 Internal Server Error

    • Body:

      {
        "error": "An error occurred while fetching properties.",
        "details": "Error message"
      }

6. Endpoint: Submit Feedback and Delete Property

Route: POST api/properties/deleteProperty

Description

This endpoint allows a user to submit feedback and delete a property. The feedback is saved and associated with the user, and the specified property is deleted from the database.

Request

  • Method: POST
  • Body:
    • propertyId (string, required): The ID of the property to be deleted.
    • userId (string, required): The ID of the user submitting the feedback.
    • feedback (string, required): The feedback provided by the user.

Response

  • Status Code: 200 OK

    • Body:
      {
        "message": "Property deleted successfully. Thank you for your feedback!"
      }
  • Status Code: 400 Bad Request

    • Body:
      {
        "error": "Property ID, User ID, Feedback are required."
      }
  • Status Code: 404 Not Found

    • Body:
      {
        "error": "Property not found."
      }
  • Status Code: 500 Internal Server Error

    • Body:
      {
        "error": "An error occurred while processing the request.",
        "details": "Error message"
      }

GET api/properties/availableProperty

Description

This endpoint retrieves all properties with the status "Active" that are not owned by the requesting user. Properties include detailed information such as reviews and the reviewers' details.


Request

URL

GET /api/properties/availableProperty

Headers

  • Content-Type: application/json

Body (JSON)

{
  "userId": "<user ID>"
}
Field Type Required Description
userId String Yes The unique ID of the user

Response

Success (200)

{
  "message": "Available properties fetched successfully.",
  "length": <number of properties>,
  "properties": [
    {
      "_id": "<property ID>",
      "name": "<property name>",
      "propertyStatus": "Active",
      "reviews": [
        {
          "_id": "<review ID>",
          "content": "<review content>",
          "user": {
            "name": "<user name>",
            "email": "<user email>"
          }
        }
      ]
      //......more details etc.
    },
    {
      //other properties
    }
  ]
}

Error Responses

  • 400 Bad Request
{
  "error": "User ID is required."
}
  • 404 Not Found
{
  "error": "User not found."
}
  • 500 Internal Server Error
{
  "error": "An error occurred while fetching available properties.",
  "details": "<error details>"
}

Notes

  • Validation: Ensures the userId field is provided in the request body.
  • Database Interaction:
    • Fetches the user by userId and populates the user's properties.
    • Retrieves properties with propertyStatus: "Active" that are not owned by the user.
    • Populates reviews and reviewer details for each property.
  • Usage: This endpoint is used to display properties available for interaction or rent by other users.

7. POST api/properties/add-review

Description

This endpoint allows a user to post a review for a specific property. The review includes a star rating and text content, which are validated before submission.


Request

URL

POST api/properties/add-review

Headers

  • Content-Type: application/json
  • Authorization: Bearer <token>

Body (JSON)

{
  "propertyId": "<property ID>",
  "stars": <number between 1 and 5>,
  "text": "<review text>"
}
Field Type Required Description
propertyId String Yes The unique ID of the property
stars Number Yes Rating between 1 and 5
text String Yes Review content

Response

Success (201)

{
  "message": "Review posted successfully",
  "review": {
    "_id": "<review ID>",
    "user": "<user ID>",
    "property": "<property ID>",
    "stars": <number>,
    "text": "<review text>"
  }
}

Error Responses

  • 400 Bad Request
{
  "error": "Missing required fields: propertyId, stars, or text"
}
  • 400 Bad Request
{
  "error": "Stars rating must be between 1 and 5"
}
  • 404 Not Found
{
  "error": "Property not found"
}
  • 500 Internal Server Error
{
  "error": "Internal server error",
  "details": "<error details>"
}

Notes

  • Validation:
    • Ensures propertyId, stars, and text are provided.
    • Validates that stars is a number between 1 and 5.
  • Database Interaction:
    • Checks if the property exists by propertyId.
    • Creates a new review and associates it with the specified property.
  • Usage: This endpoint is used for adding user feedback about properties.

8. PATCH api/properties/edit-review/:reviewId

Description

This endpoint allows a user to edit an existing review. The user can update the star rating and text content of their review.


Request

URL

PATCH api/properties/edit-review/:reviewId

Headers

  • Content-Type: application/json
  • Authorization: Bearer <token>

Path Parameters

Parameter Type Required Description
reviewId String Yes The unique ID of the review

Body (JSON)

{
  "stars": <number between 1 and 5>,
  "text": "<updated review text>"
}
Field Type Required Description
stars Number Yes Updated rating between 1 and 5
text String Yes Updated review content

Response

Success (200)

{
  "message": "Review updated successfully",
  "review": {
    "_id": "<review ID>",
    "user": "<user ID>",
    "property": "<property ID>",
    "stars": <number>,
    "text": "<updated review text>"
  }
}

Error Responses

  • 400 Bad Request
{
  "message": "Rating and comment are required"
}
  • 403 Forbidden
{
  "message": "You can only edit your own reviews"
}
  • 404 Not Found
{
  "message": "Review not found"
}
  • 500 Internal Server Error
{
  "message": "Error updating review",
  "error": "<error details>"
}

Notes

  • Validation:
    • Ensures stars and text are provided in the request body.
    • Confirms that the review belongs to the authenticated user.
  • Database Interaction:
    • Updates the star rating and text content of the specified review.
  • Usage: This endpoint is used for users to modify their submitted feedback.

9. Delete a Review

Endpoint: DELETE /api/properties/delete-review/:reviewId

Description:
This endpoint allows a user to delete their own review for a property. The user must be authenticated to access this endpoint, and they can only delete reviews they have written.


Request Parameters

  • Path Parameters:
    • reviewId (string): The ID of the review to be deleted.

Request Headers

  • Authorization: Bearer token for the authenticated user.

Response

  • 200 OK: Review deleted successfully.
    Example:

    {
      "message": "Review deleted successfully"
    }
  • 404 Not Found: If the review with the specified reviewId does not exist.
    Example:

    {
      "message": "Review not found"
    }
  • 403 Forbidden: If the user is not the owner of the review.
    Example:

    {
      "message": "You can only delete your own reviews"
    }
  • 500 Internal Server Error: If there is an error during the process.
    Example:

    {
      "message": "Error deleting review",
      "error": "Detailed error message"
    }

Behavior

  1. Validate Review: The endpoint retrieves the review using the reviewId provided. If the review is not found, a 404 Not Found response is returned.
  2. Ownership Check: The endpoint verifies that the authenticated user owns the review. If not, a 403 Forbidden response is returned.
  3. Delete Review:
    • Deletes the review from the Review collection.
    • Removes the review reference from the associated Property document.
    • Saves the updated Property document.
  4. Success Response: Returns a 200 OK response with a success message.

Error Handling

  • If any error occurs during the process, a 500 Internal Server Error response is sent, along with the error details.

Notes

  • Ensure that the user authentication middleware is correctly implemented to provide req.user.userId.
  • The reviewId must be a valid MongoDB ObjectId. Invalid IDs should be handled gracefully to avoid runtime errors.

10. Get Nearby Properties

Endpoint: GET /api/properties/nearby-properties

Description:
This endpoint allows users to find properties within a specified distance from a given geographical point (latitude and longitude). The response includes nearby properties and their associated reviews.


Request Parameters

  • Query Parameters:
    • latitude (number) [Required]: The latitude of the reference point.
    • longitude (number) [Required]: The longitude of the reference point.
    • maxDistance (number) [Required]: The maximum distance in kilometers to search for nearby properties.

Example Request

URL:

GET /api/properties/nearby-properties?latitude=28.7041&longitude=77.1025&maxDistance=5

Request Headers:

{
  "Authorization": "Bearer <your_token>"
}

Response

  • 200 OK: A list of nearby properties is returned.
    Example:

    {
      "nearbyProperties": [
        {
          "_id": "63d9f05d3e4567890abc1234",
          "name": "Sample Property",
          "location": {
            "type": "Point",
            "coordinates": [77.1234, 28.5678]
          },
          "reviews": [
            {
              "_id": "63d9f06f4e567890bca34567",
              "comment": "Great property!",
              "rating": 5
            }
          ]
        }
        //some more informations
      ]
    }
  • 400 Bad Request: If latitude, longitude, or maxDistance is missing.
    Example:

    {
      "message": "Latitude, longitude, and maxDistance are required"
    }
  • 404 Not Found: If no properties are found within the specified range.
    Example:

    {
      "message": "No nearby properties found"
    }
  • 500 Internal Server Error: If there is an error during the process.
    Example:

    {
      "message": "Server error, please try again later",
      "error": "Detailed error message"
    }

Behavior

  1. Validate Inputs: Ensures that latitude, longitude, and maxDistance are provided in the query parameters. If not, a 400 Bad Request response is returned.
  2. Convert Distance: Converts maxDistance from kilometers to meters (maxDistance * 1000).
  3. Query Database:
    • Uses MongoDB's geospatial $nearSphere operator to find properties near the specified coordinates within the maximum distance.
    • Populates the reviews field for each property.
  4. Handle Results:
    • If properties are found, returns them in a 200 OK response.
    • If no properties are found, returns a 404 Not Found response.
  5. Error Handling: Logs the error and returns a 500 Internal Server Error response with error details.

Notes

  • The location field in the Property schema must use MongoDB's 2dsphere index for geospatial queries.
  • Ensure proper validation and sanitization of query parameters to prevent injection attacks.
  • The maxDistance parameter should be validated for a reasonable range (e.g., 1–100 kilometers).

11. Endpoint: GET api/properties/category-properties

Description

This endpoint retrieves a list of properties belonging to a specific category, excluding properties owned by the authenticated user.


Request

Query Parameters
Parameter Type Required Description
category String Yes The category of the properties to retrieve.
Headers
Header Type Required Description
Authorization String Yes Bearer token for authentication.

Response

Success (200 OK)

Returns an array of properties for the specified category.

Example Response:

{
  "properties": [
    {
      "_id": "63e6c19ab0413a21a8b3c123",
      "name": "Property A",
      "category": "Residential",
      "price": 5000,
      "location": "Delhi",
      "user": "63e6c198b0413a21a8b3c122"
      //other...
    },
    {
      "_id": "63e6c1a0b0413a21a8b3c124",
      "name": "Property B",
      "category": "Residential",
      "price": 7000,
      "location": "Mumbai",
      "user": "63e6c199b0413a21a8b3c123"
      //other...
    }
  ]
}
Client Error (400 Bad Request)

Returned if the category parameter is missing.

Example Response:

{
  "message": "Category is required"
}
Not Found (404 Not Found)

Returned if no properties are found for the specified category.

Example Response:

{
  "message": "No properties found for category: Residential"
}
Server Error (500 Internal Server Error)

Returned if there is an issue with the server while processing the request.

Example Response:

{
  "message": "Server error, please try again later",
  "error": "Database connection failed"
}

Error Handling

  • Validates if category is provided in the query.
  • Catches errors during database queries and returns a generic server error response with the error message.

12. Endpoint: GET api/properties/notification/:userId

Description

This endpoint retrieves a list of notifications for a specific user, sorted in descending order by date.


Request

Path Parameters
Parameter Type Required Description
userId String Yes The ID of the user to fetch notifications for.

Response

Success (200 OK)

Returns an array of notifications for the specified user.

Example Response:

[
  {
    "_id": "63e6c19ab0413a21a8b3c125",
    "userId": "63e6c198b0413a21a8b3c123",
    "message": "Your property has been approved.",
    "date": "2024-12-31T10:15:30.000Z",
    "read": false
  },
  {
    "_id": "63e6c1a0b0413a21a8b3c126",
    "userId": "63e6c198b0413a21a8b3c123",
    "message": "A new property matches your preferences.",
    "date": "2024-12-30T08:10:15.000Z",
    "read": true
  }
]
Not Found (404 Not Found)

Returned if no notifications are found for the specified user.

Example Response:

{
  "message": "No notifications found for this user."
}
Server Error (500 Internal Server Error)

Returned if there is an issue with the server while processing the request.

Example Response:

{
  "message": "Error fetching notifications",
  "error": "Database query failed"
}

Error Handling

  • Checks if notifications exist for the specified userId. If none are found, a 404 response is returned.
  • Catches errors during database operations and returns a generic server error response with the error message.

Sorting

  • Notifications are sorted by the date field in descending order ({ date: -1 }), ensuring the most recent notifications appear first.

13. Endpoint for GET api/highlights/get-highlights

Request:

  • URL: api/highlights/get-highlights
  • Method: GET
  • Headers:
    • Authorization: Bearer <access-token> (required)

Response:

Success (200 OK):
{
  "message": "Available properties fetched successfully for the reel.",
  "properties": [
    {
      "propertyId": "63a8b3f43a123456789abcde",
      "video": "https://example.com/videos/property1.mp4",
      "user": {
        "name": "John Doe",
        "mobile": "1234567890"
      },
      "reviews": [
        {
          "user": {
            "name": "Jane Smith",
            "mobile": "0987654321"
          },
          "stars": 4,
          "text": "Great property!"
        }
      ]
    }
  ]
}
User ID Missing (400 Bad Request):
{
  "error": "User ID is required."
}
User Not Found (404 Not Found):
{
  "error": "User not found."
}
No Properties Available (404 Not Found):
{
  "message": "No available properties found.",
  "properties": []
}
Server Error (500 Internal Server Error):
{
  "error": "An error occurred while fetching available properties for the reel.",
  "details": "Error message details"
}

14. Endpoint for POST /api/wishlist/add-wishlist

Request:

  • URL: /api/wishlist/add-wishlist
  • Method: POST
  • Headers:
    • Content-Type: application/json
  • Body (JSON):
    {
      "userId": "string",
      "propertyIds": ["string", "string"]
    }

Response:

Success (201 Created):
{
  "message": "Wishlist created successfully",
  "wishlist": {
    "_id": "63a8b3f43a123456789abcde",
    "user": "63a8b3f43a123456789abcd1",
    "properties": ["63a8b3f43a123456789abcd2", "63a8b3f43a123456789abcd3"],
    "__v": 0
  }
}
Invalid Request Data (400 Bad Request):
{
  "error": "Invalid request data"
}
User Not Found (404 Not Found):
{
  "error": "User not found"
}
Some Properties Not Found (404 Not Found):
{
  "error": "Some properties not found"
}
Server Error (500 Internal Server Error):
{
  "error": "Internal server error"
}

15. Endpoint for GET /api/wishlist/get-wishlist/:userId

Request:

  • URL: /get-wishlist/:userId
  • Method: GET
  • Headers:
    • Content-Type: application/json
  • Path Parameters:
    • userId (string): The ID of the user whose wishlists are to be retrieved.

Response:

Success (200 OK):
{
  "message": "Wishlists retrieved successfully",
  "wishlists": [
    {
      "_id": "63a8b3f43a123456789abcde",
      "user": "63a8b3f43a123456789abcd1",
      "properties": [
        {
          "_id": "63a8b3f43a123456789abcd2",
          "reviews": [
            {
              "_id": "63a8b3f43a123456789abcd3",
              "user": {
                "name": "John Doe",
                "email": "john.doe@example.com"
              },
              "stars": 4,
              "text": "Great property!"
            }
          ]
        }
      ]
    }
  ]
}
User ID Missing (400 Bad Request):
{
  "error": "User ID is required"
}
User Not Found (404 Not Found):
{
  "error": "User not found"
}
No Wishlists Found (404 Not Found):
{
  "error": "No wishlists found for this user"
}
Server Error (500 Internal Server Error):
{
  "error": "Internal server error"
}

16. Documentation for Admin GET api/admin/filter-properties

Request:

  • URL: api/admin/filter-properties
  • Method: GET
  • Headers:
    • Authorization: Bearer <access-token> (required, must belong to an admin user)
    • Content-Type: application/json
  • Query Parameters:
    • propertyType (string): The type of property to filter (e.g., residential, commercial).
    • category (string): The category of the property (e.g., apartment, villa).

Response:

Success (200 OK):
[
  {
    "_id": "63a8b3f43a123456789abcde",
    "propertyType": "residential",
    "category": "apartment",
    "user": {
      "name": "John Doe",
      "email": "john.doe@example.com",
      "role": "user",
      "whatsappMobile": "9876543210"
    }
    //other details
  }
]
Missing Required Fields (400 Bad Request):
{
  "message": "Please provide all required fields: propertyType, category, and role."
}
Unauthorized (403 Forbidden):
{
  "message": "You are not an admin"
}
No Properties Found (404 Not Found):
{
  "message": "No properties found matching the criteria."
}
Server Error (500 Internal Server Error):
{
  "message": "Server error",
  "error": "Error message details"
}

Documentation for GET /api/admin/get-users

Request:

  • URL: /api/admin/get-users
  • Method: GET
  • Headers:
    • Authorization: Bearer <access-token> (required, must belong to an admin user)
    • Content-Type: application/json

Response:

Success (200 OK):
[
  {
    "_id": "63a8b3f43a123456789abcde",
    "name": "John Doe",
    "mobile": "9876543210",
    "city": "New York",
    "email": "john.doe@example.com",
    "role": "user",
    "whatsappMobile": "9876543210",
    "feedbacksGiven": [
      {
        "_id": "63a8b3f43a123456789abcd1",
        "feedbackText": "Great platform!"
      }
    ],
    "reviews": [
      {
        "_id": "63a8b3f43a123456789abcd2",
        "stars": 5,
        "text": "Excellent service!"
      }
    ]
    //other details
  }
]
Unauthorized (403 Forbidden):
{
  "message": "You are not an admin"
}
No Users Found (404 Not Found):
{
  "message": "No users found."
}
Server Error (500 Internal Server Error):
{
  "message": "Server error while fetching users.",
  "error": "Error message details"
}

Documentation for POST api/admin/post-notifications

Request:

  • URL: api/admin/post-notifications
  • Method: POST
  • Headers:
    • Authorization: Bearer <access-token> (required, must belong to an admin user)
    • Content-Type: application/json
  • Body (JSON):
    {
      "userId": "string",
      "heading": "string",
      "text": "string"
    }

Response:

Success (200 OK):
{
  "message": "Notification sent successfully"
}
Missing Required Fields (400 Bad Request):
{
  "message": "userId, heading, and text are required"
}
Unauthorized (403 Forbidden):
{
  "message": "You are not an admin"
}
User Not Found (404 Not Found):
{
  "message": "User not found"
}
Server Error (500 Internal Server Error):
{
  "message": "Error sending notification",
  "error": "Error message details"
}

About

Backend

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •