Skip to content

Commit

Permalink
Add product recalls
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeeey committed Jun 18, 2024
1 parent d49f9f0 commit a62add7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 2 deletions.
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"host": "127.0.0.1",
"port": 3306,
"user": "root",
"password": "",
"database": ""
"password": "password123",
"database": "opendata"
}
}
14 changes: 14 additions & 0 deletions setup/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,18 @@ CREATE TABLE `recyclingCentreServices` (
`service` varchar(50) NOT NULL,
FOREIGN KEY (`recyclingCentreId`) REFERENCES `recyclingCentres`(`id`) ON DELETE CASCADE,
PRIMARY KEY (`id`)
);

CREATE TABLE `productRecalls` (
`id` int NOT NULL,
`title` varchar(150) NOT NULL,
`imageUrl` varchar(250),
`brand` varchar(120) NOT NULL,
`recallDate` timestamp NOT NULL,
`packSize` varchar(220),
`batchCodes` text,
`problem` text,
`furtherInformation` text,
`websiteUrl` varchar(250),
PRIMARY KEY (`id`)
);
5 changes: 5 additions & 0 deletions src/routes/v1/carparks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ router.get("/live-spaces", cache("1 minute", onlyApiSuccess), async (req, res) =
return res.json(JSON.parse(json));
});

router.get("/test-spaces", async (req, res) => {
const query = await mysql.execute('SELECT * FROM liveparkingspaces ORDER BY createdAt DESC LIMIT 1588');
return res.json(query);
});

router.use(errorHandler);

export default router;
1 change: 1 addition & 0 deletions src/routes/v1/eatsafe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// https://sojopendata.azurewebsites.net/eatsafe/json?t=5728976
19 changes: 19 additions & 0 deletions src/routes/v1/product-recalls.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import apicache from "apicache";
import { Router } from "express";
import mysql from "../../mysql";
import errorHandler from "../../utils/error-handler";
import { onlyApiSuccess } from "../../utils/utils";

const router = Router();
const cache = apicache.middleware;

router.get("/", async (req, res) => {
const results = await mysql.execute(`
SELECT * FROM productRecalls
`);
return res.json({ results });
});

router.use(errorHandler);

export default router;
2 changes: 2 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import carparksRoute from "./routes/v1/carparks";
import vehiclesRoute from "./routes/v1/vehicles";
import recyclingRoute from "./routes/v1/recycling";
import defibrillatorsRoute from "./routes/v1/defibrillators";
import productRecallsRoute from "./routes/v1/product-recalls";
import errorHandler from "./utils/error-handler";
import { ErrorCode } from "./utils/errors/ErrorCode";
import { RouteError } from "./utils/errors/RouteError";
Expand All @@ -31,6 +32,7 @@ app.use("/v1/carparks", carparksRoute);
app.use("/v1/vehicles", vehiclesRoute);
app.use("/v1/recycling", recyclingRoute);
app.use("/v1/defibrillators", defibrillatorsRoute);
app.use("/v1/product-recalls", productRecallsRoute);

// Handle 404 errors
app.use("*", (req, res) => {
Expand Down

0 comments on commit a62add7

Please sign in to comment.