mirror of
				https://github.com/Djeeberjr/fw-anwesenheit.git
				synced 2025-11-04 07:34:10 +00:00 
			
		
		
		
	added new routes & more mock data to server mock
This commit is contained in:
		
							parent
							
								
									bd3f6731fd
								
							
						
					
					
						commit
						f5d4ae1e05
					
				
							
								
								
									
										99
									
								
								web/mock/data.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										99
									
								
								web/mock/data.json
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,99 @@
 | 
				
			|||||||
 | 
					{
 | 
				
			||||||
 | 
					  "mapping": [
 | 
				
			||||||
 | 
					    [
 | 
				
			||||||
 | 
					      "123456789ABC",
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "first": "Feuerwehrman",
 | 
				
			||||||
 | 
					        "last": "Sam"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    [
 | 
				
			||||||
 | 
					      "A1B2C3D4E5F6",
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "first": "Luna",
 | 
				
			||||||
 | 
					        "last": "Starforge"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    [
 | 
				
			||||||
 | 
					      "0F1E2D3C4B5A",
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "first": "Gareth",
 | 
				
			||||||
 | 
					        "last": "Ironwill"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    [
 | 
				
			||||||
 | 
					      "ABCDEF123456",
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "first": "Nina",
 | 
				
			||||||
 | 
					        "last": "Skylark"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    [
 | 
				
			||||||
 | 
					      "654321FEDCBA",
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "first": "Tobias",
 | 
				
			||||||
 | 
					        "last": "Marrow"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    [
 | 
				
			||||||
 | 
					      "DEADBEEFCAFE",
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "first": "Astra",
 | 
				
			||||||
 | 
					        "last": "Vale"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    [
 | 
				
			||||||
 | 
					      "BADA55C0FFEE",
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "first": "Rowan",
 | 
				
			||||||
 | 
					        "last": "Tempest"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    [
 | 
				
			||||||
 | 
					      "C001D00D1337",
 | 
				
			||||||
 | 
					      {
 | 
				
			||||||
 | 
					        "first": "Juniper",
 | 
				
			||||||
 | 
					        "last": "Voss"
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					  ],
 | 
				
			||||||
 | 
					  "days": [
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "date": 20372,
 | 
				
			||||||
 | 
					      "ids": [
 | 
				
			||||||
 | 
					        "123456789ABC",
 | 
				
			||||||
 | 
					        "A1B2C3D4E5F6"
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "date": 20373,
 | 
				
			||||||
 | 
					      "ids": [
 | 
				
			||||||
 | 
					        "0F1E2D3C4B5A",
 | 
				
			||||||
 | 
					        "ABCDEF123456"
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "date": 20374,
 | 
				
			||||||
 | 
					      "ids": [
 | 
				
			||||||
 | 
					        "654321FEDCBA",
 | 
				
			||||||
 | 
					        "DEADBEEFCAFE",
 | 
				
			||||||
 | 
					        "BADA55C0FFEE"
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "date": 20375,
 | 
				
			||||||
 | 
					      "ids": [
 | 
				
			||||||
 | 
					        "C001D00D1337",
 | 
				
			||||||
 | 
					        "A1B2C3D4E5F6",
 | 
				
			||||||
 | 
					        "123456789ABC"
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					      "date": 20376,
 | 
				
			||||||
 | 
					      "ids": [
 | 
				
			||||||
 | 
					        "N0T3X1ST1D0",
 | 
				
			||||||
 | 
					        "654321FEDCBA"
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					  ]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@ -1,20 +1,14 @@
 | 
				
			|||||||
import express from "express";
 | 
					import express from "express";
 | 
				
			||||||
import bodyParser from "body-parser";
 | 
					import bodyParser from "body-parser";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import mockData from "./data.json" with {type: "json"};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const app = express();
 | 
					const app = express();
 | 
				
			||||||
const port = 3000;
 | 
					const port = 3000;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
app.use(bodyParser.json());
 | 
					const SECS_IN_DAY = 86_400;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
let mappings = [
 | 
					app.use(bodyParser.json());
 | 
				
			||||||
  [
 | 
					 | 
				
			||||||
    "123456789ABC",
 | 
					 | 
				
			||||||
    {
 | 
					 | 
				
			||||||
      first: "Feuerwehrman",
 | 
					 | 
				
			||||||
      last: "Sam",
 | 
					 | 
				
			||||||
    },
 | 
					 | 
				
			||||||
  ],
 | 
					 | 
				
			||||||
];
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
function generateRandomId() {
 | 
					function generateRandomId() {
 | 
				
			||||||
  const chars = "ABCDEF0123456789";
 | 
					  const chars = "ABCDEF0123456789";
 | 
				
			||||||
@ -27,7 +21,7 @@ function generateRandomId() {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
// GET /api/mapping
 | 
					// GET /api/mapping
 | 
				
			||||||
app.get("/api/mapping", (req, res) => {
 | 
					app.get("/api/mapping", (req, res) => {
 | 
				
			||||||
  res.json(mappings);
 | 
					  res.json(mockData.mapping);
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// POST /api/mapping
 | 
					// POST /api/mapping
 | 
				
			||||||
@ -45,11 +39,45 @@ app.post("/api/mapping", (req, res) => {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Add new mapping
 | 
					  // Add new mapping
 | 
				
			||||||
  mappings.push([id, name]);
 | 
					  mockData.mappings.push([id, name]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  res.status(201).send("");
 | 
					  res.status(201).send("");
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app.get("/api/day", (req, res) => {
 | 
				
			||||||
 | 
					  let day;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (req.query.day) {
 | 
				
			||||||
 | 
					    day = parseInt(req.query.day, 10);
 | 
				
			||||||
 | 
					  }else if (req.query.timestamp) {
 | 
				
			||||||
 | 
					    let ts = parseInt(req.query.timestamp, 10);
 | 
				
			||||||
 | 
					    day = ts / SECS_IN_DAY;
 | 
				
			||||||
 | 
					  }else {
 | 
				
			||||||
 | 
					    return res.status(400).json({ error: "Missing or invalid 'day' parameter" });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (isNaN(day)) {
 | 
				
			||||||
 | 
					    return res.status(400).json({ error: "Missing or invalid 'day' parameter" });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let foundDay = mockData.days.find(e => e.date == day);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  if (!foundDay) {
 | 
				
			||||||
 | 
					    return res.status(404).send("Not found");
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  res.status(200).json(foundDay);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					app.get("/api/days", (req,res) => {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let qFrom = parseInt(req.query.from) / SECS_IN_DAY;
 | 
				
			||||||
 | 
					  let qTo = parseInt(req.query.to) / SECS_IN_DAY;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  let days = mockData.days.filter(e => e.date >= qFrom && e.date <= qTo).map(e => e.date);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  res.status(200).json(days);
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// SSE route: /api/idevent
 | 
					// SSE route: /api/idevent
 | 
				
			||||||
app.get("/api/idevent", (req, res) => {
 | 
					app.get("/api/idevent", (req, res) => {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user