Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Desafio FrontEnd #27

Closed
wants to merge 8 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: 🐛 resolve get data in json file
Indiorlei committed Nov 11, 2023
commit 9a2bcd64d8ae51971c7611fd425ace18c59b0f0d
Binary file modified src/.DS_Store
Binary file not shown.
Binary file modified src/app/.DS_Store
Binary file not shown.
8 changes: 6 additions & 2 deletions src/app/api/tracking/route.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { NextRequest, NextResponse } from "next/server";
import { promises as fs } from "fs";

export async function GET(request: NextRequest) {
const { searchParams } = new URL(request.url);
const trackingCode = searchParams.get("trackingCode");

if (!trackingCode) return NextResponse.json({});

const response = await fetch("http://localhost:3000/tracking.json");
const data = await response.json();
const file = await fs.readFile(
process.cwd() + "/src/app/lib/tracking.json",
"utf8"
);
const data = JSON.parse(file);

const deliveryFound = data.find(
(item: { order_number: string }) => item.order_number === trackingCode
File renamed without changes.
4 changes: 1 addition & 3 deletions src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -31,9 +31,7 @@ export default function HomePage() {
};

const getTracking = useCallback(async () => {
const response = await fetch(
`http://localhost:3000/api/tracking?trackingCode=${trackingCode}`
);
const response = await fetch(`api/tracking?trackingCode=${trackingCode}`);
const { data, hasError } = await response.json();

setError(hasError);