fix: handle undefined slug and doctorId in cache functions
This commit is contained in:
@@ -11,6 +11,7 @@ import { imageUrl } from "@/helper";
|
|||||||
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
||||||
|
|
||||||
const getClinic = cache(async (slug) => {
|
const getClinic = cache(async (slug) => {
|
||||||
|
if (!slug || slug === "undefined") return null;
|
||||||
const res = await fetch(`${API_URL}/api/v1/clinic/${slug}`, {
|
const res = await fetch(`${API_URL}/api/v1/clinic/${slug}`, {
|
||||||
next: { revalidate: 3600, tags: [`clinic-${slug}`] },
|
next: { revalidate: 3600, tags: [`clinic-${slug}`] },
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ const API_URL = process.env.NEXT_PUBLIC_API_URL;
|
|||||||
const FALLBACK_IMG = "https://nobat724.com/assets/images/logo.png";
|
const FALLBACK_IMG = "https://nobat724.com/assets/images/logo.png";
|
||||||
|
|
||||||
const getDoctor = cache(async (slug) => {
|
const getDoctor = cache(async (slug) => {
|
||||||
|
if (!slug || slug === "undefined") return null;
|
||||||
const res = await fetch(`${API_URL}/api/v1/doctor/${slug}`, {
|
const res = await fetch(`${API_URL}/api/v1/doctor/${slug}`, {
|
||||||
next: { revalidate: 3600, tags: [`doctor-${slug}`] },
|
next: { revalidate: 3600, tags: [`doctor-${slug}`] },
|
||||||
});
|
});
|
||||||
@@ -21,6 +22,7 @@ const getDoctor = cache(async (slug) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const getDoctorAddresses = cache(async (doctorId) => {
|
const getDoctorAddresses = cache(async (doctorId) => {
|
||||||
|
if (!doctorId) return [];
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`${API_URL}/api/v1/clinic-pro/doctor-addresses/${doctorId}`, {
|
const res = await fetch(`${API_URL}/api/v1/clinic-pro/doctor-addresses/${doctorId}`, {
|
||||||
next: { revalidate: 3600, tags: [`doctor-addresses-${doctorId}`] },
|
next: { revalidate: 3600, tags: [`doctor-addresses-${doctorId}`] },
|
||||||
|
|||||||
Reference in New Issue
Block a user