feat: fileService.ts

This commit is contained in:
Lucàs
2024-09-20 22:08:00 +02:00
parent b8d5751374
commit 0382499c0d
15 changed files with 1415 additions and 16 deletions
+20
View File
@@ -0,0 +1,20 @@
import { Router, Request, Response } from "express";
import fileService from "../../services/fileService";
const router = Router();
router.get("/data/nudger", (req: Request, res: Response) => {
fileService
.downloadAndExtract("https://nudger.fr/opendata/gtin-open-data.zip")
.then(() => {
res.status(200).json({
status: "SUCCESS",
message: "Data nudger downloaded and extracted",
});
})
.catch((error) => {
res.status(500).json({ status: "ERROR", message: error.message });
});
});
export default router;
+22
View File
@@ -0,0 +1,22 @@
import { Router, Request, Response } from "express";
import fileService from "../../services/fileService";
const router = Router();
router.get("/data/openfoodfacts", (req: Request, res: Response) => {
fileService
.downloadAndExtract(
"https://static.openfoodfacts.org/data/en.openfoodfacts.org.products.csv.gz"
)
.then(() => {
res.status(200).json({
status: "SUCCESS",
message: "Data openfoodfacts downloaded and extracted",
});
})
.catch((error) => {
res.status(500).json({ status: "ERROR", message: error.message });
});
});
export default router;
+5
View File
@@ -0,0 +1,5 @@
import randomizeRouter from "./randomize";
import nudgerRouter from "./data/nudger";
import openDataRouter from "./data/openfoodfacts";
export default [randomizeRouter, nudgerRouter, openDataRouter];
+14
View File
@@ -0,0 +1,14 @@
import { Router, Request, Response } from "express";
const router = Router();
router.post("/randomize", (req: Request, res: Response) => {
// TODO: Implement randomize route
// TODO: Parse the DMN file
// TODO:
res.status(200).json({ status: "RANDOMIZED", data: [{}] });
});
export default router;