Package Exports
- saksh-real-estate
- saksh-real-estate/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (saksh-real-estate) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
Saksh Real Estate
A powerful Node.js package designed for managing properties and generating personalized recommendations using ChatGPT.
Features
- Property Management: Create, read, update, and delete properties effortlessly.
- Advanced Search: Search properties based on various criteria such as location, type, price range, and more.
- Similar Properties: Discover properties similar to a given property based on location, type, and price range.
- Property Recommendations: Generate tailored property recommendations based on user browsing history and preferences using ChatGPT.
- Predict Property Value: Leverage AI to predict the value of a property.
- Change Logs: Maintain a comprehensive log of changes made to properties.
Installation
To install the package, use npm:
npm install saksh-real-estateUsage
Setting Up
Begin by setting up your Express server and MongoDB connection:
const express = require('express');
const mongoose = require('mongoose');
const SakshPropertyClass = require('saksh-real-estate/classes/SakshPropertyClass');
const SakshChatGPTClass = require('saksh-real-estate/classes/SakshChatGPTClass');
const app = express();
app.use(express.json());
mongoose.connect('mongodb://localhost:27017/real-estate', {
useNewUrlParser: true,
useUnifiedTopology: true
});
// Middleware to simulate a logged-in user
const fakeAuth = (req, res, next) => {
req.user = { id: 'fakeUserId', name: 'Fake User' };
next();
};
app.use(fakeAuth);
// Initialize SakshPropertyClass and SakshChatGPTClass with your OpenAI API key
const propertyClass = new SakshPropertyClass();
const chatGPTClass = new SakshChatGPTClass('your-openai-api-key');
// Define your routes here...
app.listen(3000, () => {
console.log('Server is running on port 3000');
});Event Handling with SakshChatGPTClass
You can enhance your application by using event handling with the SakshChatGPTClass. Here’s how:
const SakshChatGPTClass = require('./SakshChatGPTClass');
const chatGPT = new SakshChatGPTClass('your-openai-api-key');
chatGPT.on('requestStarted', (data) => {
console.log('Request started:', data);
});
chatGPT.on('requestCompleted', (data) => {
console.log('Request completed:', data);
});
chatGPT.on('requestFailed', (data) => {
console.error('Request failed:', data);
});
chatGPT.on('recommendationStarted', (data) => {
console.log('Recommendation started:', data);
});
chatGPT.on('recommendationCompleted', (data) => {
console.log('Recommendation completed:', data);
});
chatGPT.on('recommendationFailed', (data) => {
console.error('Recommendation failed:', data);
});
// Example usage
(async () => {
try {
const browsingHistory = { /* your browsing history data */ };
const userPreferences = { /* your user preferences data */ };
const result = await chatGPT.sakshRecommendPropertiesFromHistory(browsingHistory, userPreferences);
console.log('Recommendations:', result);
} catch (error) {
console.error('Error:', error);
}
})();Event Handling with SakshPropertyClass
You can also handle events related to property management with the SakshPropertyClass. Here’s how:
propertyClass.on('propertyCreated', (property) => {
console.log(`Property created: ${property._id}`);
});
propertyClass.on('propertyUpdated', (property) => {
console.log(`Property updated: ${property._id}`);
});
propertyClass.on('propertyDeleted', (property) => {
console.log(`Property deleted: ${property._id}`);
});
// Create a new property
propertyClass.sakshCreate({
address: '123 Main St',
price: 500000,
location: 'Downtown',
type: 'Apartment',
bedrooms: 2,
bathrooms: 2,
amenities: ['Gym', 'Pool']
}).then(property => {
console.log('Created property:', property);
}).catch(error => {
console.error('Error creating property:', error);
});API Endpoints
Create Property
app.post('/properties', async (req, res) => {
try {
const property = await propertyClass.sakshCreate(req.body);
res.status(201).send(property);
} catch (error) {
res.status(400).send(error);
}
});Read Properties
app.get('/properties', async (req, res) => {
try {
const properties = await propertyClass.sakshGetAll();
res.send(properties);
} catch (error) {
res.status(500).send();
}
});Update Property
app.patch('/properties/:id', async (req, res) => {
try {
const property = await propertyClass.sakshUpdate(req.params.id, req.body);
res.send(property);
} catch (error) {
res.status(400).send(error.message);
}
});Delete Property
app.delete('/properties/:id', async (req, res) => {
try {
const property = await propertyClass.sakshDelete(req.params.id);
res.send(property);
} catch (error) {
res.status(500).send(error.message);
}
});Predict Property Value
app.get('/properties/:id/predict', async (req, res) => {
try {
const predictedValue = await chatGPTClass.sakshGenerateResponse(req.params.id);
res.send({ predictedValue });
} catch (error) {
res.status(500).send(error.message);
}
});Get Similar Properties
app.get('/properties/:id/similar', async (req, res) => {
try {
const similarProperties = await propertyClass.sakshGetSimilarProperties(req.params.id);
res.send(similarProperties);
} catch (error) {
res.status(500).send(error.message);
}
});Recommend Properties Based on Browsing History and User Preferences
app.post('/properties/recommend/history', async (req, res) => {
try {
const { browsingHistory, userPreferences } = req.body;
const { recommendations, recommendedProperties } = await chatGPTClass.sakshRecommendPropertiesFromHistory(browsingHistory, userPreferences);
res.send({ recommendations, recommendedProperties });
} catch (error) {
res.status(500).send(error.message);
}
});Example Request
Here’s an example of the data you can pass in the req.body for the /properties/recommend/history endpoint:
{
"browsingHistory": {
"viewedProperties": [
{
"id": "property1",
"location": "Downtown",
"type": "Apartment",
"price": 500000,
"bedrooms": 2,
"bathrooms": 2,
"amenities": ["Gym", "Pool"]
},
{
"id": "property2",
"location": "Suburbs",
"type": "House",
"price": 750000,
"bedrooms": 3,
"bathrooms": 3,
"amenities": ["Garage", "Garden"]
}
],
"savedProperties": [
{
"id": "property3",
"location": "Downtown",
"type": "Apartment",
"price": 600000,
"bedrooms": 2,
"bathrooms": 2,
"amenities": ["Gym", "Pool"]
}
]
},
"userPreferences": {
"location": "Downtown",
"type": "Apartment",
"minPrice": 400000,
"maxPrice": 700000,
"bedrooms": 2,
"bathrooms": 2,
"amenities": ["Gym", "Pool"]
}
}License
MIT
Contact
For any inquiries or support, please contact: susheel2339@gmail.com