Skip to content

Commit

Permalink
added functions, views and urls
Browse files Browse the repository at this point in the history
  • Loading branch information
BaderOukhai committed Dec 8, 2023
1 parent 8042fa3 commit 8658cde
Show file tree
Hide file tree
Showing 2,318 changed files with 275,132 additions and 137 deletions.
53 changes: 53 additions & 0 deletions functions/get-dealership.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;
const Cloudant = require('@cloudant/cloudant');
// Initialize Cloudant connection with IAM authentication
async function dbCloudantConnect() {
try {
const cloudant = Cloudant({
plugins: { iamauth: { iamApiKey: 'gZR6u2C6-5oPNpg6TL9k1-BHGmefkotAlP_65ZJI0BkF' } }, // Replace with your IAM API key
url: 'https://d0c6fba4-de9e-4d5e-9ebb-c481b50fc836-bluemix.cloudantnosqldb.appdomain.cloud', // Replace with your Cloudant URL
});
const db = cloudant.use('dealerships');
console.info('Connect success! Connected to DB');
return db;
} catch (err) {
console.error('Connect failure: ' + err.message + ' for Cloudant DB');
throw err;
}
}
let db;
(async () => {
db = await dbCloudantConnect();
})();
app.use(express.json());
// Define a route to get all dealerships with optional state and ID filters
app.get('/dealerships/get', (req, res) => {
const { state, id } = req.query;
// Create a selector object based on query parameters
const selector = {};
if (state) {
selector.state = state;
}

if (id) {
selector.id = parseInt(id); // Filter by "id" with a value of 1
}
const queryOptions = {
selector,
limit: 10, // Limit the number of documents returned to 10
};
db.find(queryOptions, (err, body) => {
if (err) {
console.error('Error fetching dealerships:', err);
res.status(500).json({ error: 'An error occurred while fetching dealerships.' });
} else {
const dealerships = body.docs;
res.json(dealerships);
}
});
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});
71 changes: 0 additions & 71 deletions functions/get_dealership.js

This file was deleted.

46 changes: 0 additions & 46 deletions functions/get_reviews.py

This file was deleted.

1 change: 1 addition & 0 deletions functions/node_modules/.bin/follow

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions functions/node_modules/.bin/mime

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions functions/node_modules/.bin/sshpk-conv

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions functions/node_modules/.bin/sshpk-sign

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions functions/node_modules/.bin/sshpk-verify

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions functions/node_modules/.bin/uuid

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 8658cde

Please sign in to comment.