Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed unused mongo package and connected with mongoose. #73

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
128 changes: 52 additions & 76 deletions api/api_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,103 +3,79 @@ const mongoose = require("mongoose");
const app = express();
const port = 3000;

// I'm confused what this bit is for?
const { MongoClient, ServerApiVersion } = require("mongodb");

// MongoDB URI
const uri = "mongodb+srv://2455344:hello12345@unicluster.0xfojui.mongodb.net/?retryWrites=true&w=majority";
const uri =
"mongodb+srv://2455344:hello12345@unicluster.0xfojui.mongodb.net/?retryWrites=true&w=majority";

// Middleware
app.use(express.json());

mongoose.connect(uri);


// Create a MongoClient with a MongoClientOptions object to set the Stable API version
const client = new MongoClient(uri, {
serverApi: {
version: ServerApiVersion.v1,
strict: true,
deprecationErrors: true,
},
});


async function run() {
try {
// Connect the client to the server (optional starting in v4.7)
await client.connect();
// Send a ping to confirm a successful connection
await client.db("admin").command({ ping: 1 });
console.log(
"Pinged your deployment. You successfully connected to MongoDB!"
);
} finally {
// Ensures that the client will close when you finish/error
await client.close();
}
}
run().catch(console.dir);

const db = mongoose.connection;

// ATM Schema
const atmSchema = new mongoose.Schema({
Identification: String,
SupportedLanguages: [String],
ATMServices: [String],
Accessibility: [String],
Access24HoursIndicator: Boolean,
SupportedCurrencies: [String],
MinimumPossibleAmount: String,
Note: [String],
OtherAccessibility: [
{
Code: String,
Name: String,
Description: String,
},
],
Branch: {
Identification: String,
SupportedLanguages: [String],
ATMServices: [String],
Accessibility: [String],
Access24HoursIndicator: Boolean,
SupportedCurrencies: [String],
MinimumPossibleAmount: String,
Note: [String],
OtherAccessibility: [{
},
Location: {
LocationCategory: [String],
OtherLocationCategory: [
{
Code: String,
Name: String,
Description: String
}],
Branch: {
Identification: String
Description: String,
},
],
Site: {
Identification: String,
Name: String,
},
Location: {
LocationCategory: [String],
OtherLocationCategory: [{
Code: String,
Name: String,
Description: String
}],
Site: {
Identification: String,
Name: String
PostalAddress: {
StreetName: String,
TownName: String,
CountrySubDivision: [String],
Country: String,
PostCode: String,
GeoLocation: {
GeographicCoordinates: {
Latitude: String,
Longitude: String,
},
PostalAddress: {
StreetName: String,
TownName: String,
CountrySubDivision: [String],
Country: String,
PostCode: String,
GeoLocation: {
GeographicCoordinates: {
Latitude: String,
Longitude: String
}
}
}
}
},
},
},
});

const ATM = mongoose.model('ATM', atmSchema);

const ATM = mongoose.model("ATM", atmSchema);

// API Endpoints
app.get("/", (req, res) => res.send("Hello World!"));

// Endpoint to get ATMs
app.get('/atms', async (req, res) => {
try {
const atms = await ATM.find({});
res.json(atms);
} catch (error) {
res.status(500).send(error);
}
app.get("/atms", async (req, res) => {
try {
const atms = await ATM.find({});
res.json(atms);
} catch (error) {
res.status(500).send(error);
}
});

// Listen on the specified port
Expand Down
Loading