Skip to content

Commit

Permalink
Updated Wagon API and QR code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Spytex committed Jul 18, 2023
1 parent d924f1c commit 6dc7639
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 37 deletions.
65 changes: 35 additions & 30 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
"formidable": "^3.5.0",
"framer-motion": "^10.12.18",
"next": "13.4.9",
"qrcode.react": "^3.1.0",
"react": "18.2.0",
"react-barcode": "^1.4.6",
"react-dom": "18.2.0",
"react-icons": "^4.10.1",
"react-qr-code": "^2.0.11",
"react-query": "^3.39.3",
"typescript": "5.1.6"
"typescript": "5.1.6",
"uuid-by-string": "^4.0.0"
}
}
2 changes: 1 addition & 1 deletion src/components/ui/wagon/WagonItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { FC, useRef, useState } from "react";
import { IWagonDataSingle } from "@/interfaces/wagon.interface";
import {Box, Button, Center, Flex, Link, Text, useToast, VStack} from "@chakra-ui/react";
import { PhotoService } from "@/service/photo.service";
import QRCode from "react-qr-code";
import QRCode from "qrcode.react";
import Barcode from "react-barcode";

export const WagonItem: FC<IWagonDataSingle> = ({ Vagons }) => {
Expand Down
20 changes: 16 additions & 4 deletions src/pages/api/wagons.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,27 @@
import { NextApiRequest, NextApiResponse } from 'next';
import {WagonService} from "@/service/wagon.service";
import { WagonService } from '@/service/wagon.service';
import getUuidByString from 'uuid-by-string';

const wordID = 'WagonInfo';

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
const { query } = req;
const VagonNumber = query.VagonNumber as string;
const apiKey = query.apiKey as string;

if (!VagonNumber) {
// Validate the apiKey (UUID v5)
if (!apiKey || !validateUuid(apiKey)) {
return res.status(400).json({ error: 'Invalid API key' });
}

const wagonNumber = query.VagonNumber as string;

if (!wagonNumber) {
const wagons = await WagonService.getAll();
return res.status(200).json(wagons);
}

const wagon = await WagonService.getOne(VagonNumber);
const wagon = await WagonService.getOne(wagonNumber);

if (!wagon) {
return res.status(404).json({ error: 'Wagon not found' });
Expand All @@ -25,3 +34,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}
}

function validateUuid(uuid: string): boolean {
return getUuidByString(wordID) === uuid;
}

0 comments on commit 6dc7639

Please sign in to comment.