Skip to content

Commit

Permalink
feat(api): Added some more GET endpoints and improved some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
FinnbarHome committed Jan 23, 2024
1 parent d347a0b commit 21e2dc5
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions api/api_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ db.once("open", () => {
});

// ATM ENDPOINTS

// GET FUNCTIONS
// GET all ATMs
app.get("/api/atms", async (req, res) => {
try {
Expand All @@ -46,6 +48,33 @@ app.get("/api/atms/:id", async (req, res) => {
}
});

// GET ATM services by Identification
app.get("/api/atms/:id/services", async (req, res) => {
try {
const atm = await db
.collection("ATMs")
.findOne({ Identification: req.params.id }, { projection: { ATMServices: 1 } });
res.json(atm.ATMServices || []);
} catch (error) {
res.status(500).json({ error: error.message });
}
});

// GET ATMs with search functionality
app.get("/api/atms/search", async (req, res) => {
try {
const query = {}; // Construct query based on req.query parameters
// Example: if (req.query.location) query['Location.TownName'] = req.query.location;
const atms = await db.collection("ATMs").find(query).toArray();
res.json(atms);
} catch (error) {
res.status(500).json({ error: error.message });
}
});



// UPDATE FUNCTIONS
// UPDATE an ATM by Identification
app.put("/api/atms/:id", async (req, res) => {
try {
Expand All @@ -62,6 +91,7 @@ app.put("/api/atms/:id", async (req, res) => {
}
});

// DELETE FUNCTIONS
// DELETE an ATM by Identification
app.delete("/api/atms/:id", async (req, res) => {
try {
Expand All @@ -77,6 +107,7 @@ app.delete("/api/atms/:id", async (req, res) => {
}
});

// POST FUNCTIONS
// POST a new ATM
app.post("/api/atms", async (req, res) => {
try {
Expand All @@ -88,18 +119,6 @@ app.post("/api/atms", async (req, res) => {
}
});

// GET ATMs with search functionality
app.get("/api/atms/search", async (req, res) => {
try {
const query = {}; // Construct query based on req.query parameters
// Example: if (req.query.location) query['Location.TownName'] = req.query.location;
const atms = await db.collection("ATMs").find(query).toArray();
res.json(atms);
} catch (error) {
res.status(500).json({ error: error.message });
}
});


// BRANCH ENDPOINTS

Expand Down

0 comments on commit 21e2dc5

Please sign in to comment.