Skip to content

Commit

Permalink
using native fetch for caching and revalidation
Browse files Browse the repository at this point in the history
  • Loading branch information
Bahugunajii committed Jan 4, 2024
1 parent e4b1a1b commit b038c05
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 14 deletions.
1 change: 0 additions & 1 deletion api/afdb/library.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use server"

import axios from 'axios';
import { Curriculum, Subject, Grade, Chapter, Resource, Topic } from '../../app/types'
import getFetchConfig from '../fetchConfig';

Expand Down
1 change: 0 additions & 1 deletion api/afdb/session.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use server"

import axios from 'axios';
import getFetchConfig from '../fetchConfig';

const url = process.env.AF_DB_SERVICE_URL;
Expand Down
17 changes: 9 additions & 8 deletions api/reporting/reports.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
"use server"

import { api } from "@/services/url";
import axios from "axios";
import getFetchConfig from "../fetchConfig";

export async function getReports(userId: string) {
const apiKey = process.env.AF_REPORTS_DB_API_KEY;
const url = `${api.reports.baseUrl}${api.reports.student_reports}${userId}?format=json`;

try {
const responseData = await axios.get(url, {
headers: {
accept: "application/json",
Authorization: `Bearer ${apiKey}`,
},
});
return responseData.data;
const response = await fetch(url, getFetchConfig(apiKey!));

if (!response.ok) {
throw new Error(`Error fetching reports: ${response.statusText}`);
}

const data = await response.json();
return data;
} catch (error) {
throw error;
}
Expand Down
3 changes: 0 additions & 3 deletions app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ export interface ReportsListProps {
userId: string;

}
export interface AxiosAdditionalHeaders {
[key: string]: string;
}

export interface User {
id: number;
Expand Down
2 changes: 1 addition & 1 deletion services/AuthContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function AuthProvider({ children }: { children: React.ReactNode }) {
checkToken();
}, []);

const userName = user ? `${user.first_name} ${user.last_name}` : '';
const userName = `${user?.first_name || ''} ${user?.last_name || ''}`.trim();
const userDbId = user ? user.id : null;

return (
Expand Down

0 comments on commit b038c05

Please sign in to comment.