I developing a course app while creating a course I got this following error which appears, I try to change structure of my code but it fails. Using Nextjs
TypeScript
export const createCourse = async (course: Course) => {
  const {course_id } = course;
  const now = new Date().toISOString();
  const validCourseId = generateValidPostId(course_id);
  const videoId = generateValidId();
  console.log('Creating course', course);
  try {
    const { databases, storage } = await createAdminClient();
    if (!databases || !storage) {
      throw new Error("Failed to initialize Appwrite databases or storage clients");
    }
    console.log('Database and storage clients initialized');
    if (!course.video) {
      throw new Error('Course video is required');
    };
    const courseVideo = await storage.createFile(postAttachementBucket, videoId, course.video);
    console.log('Course video uploaded', courseVideo);
    const modules = await databases.createDocument(db, courseCollection, validCourseId, {
      ...course,
      user_id: course.user_id,
      video: courseVideo.$id,
      created_at: now,
      update_at: now,
    });
    console.log('Course created', modules);
    return parseStringify(modules);
  } catch (error) {
    console.log('Error creating course', error);
  }
};
the following function is parseStringify
TypeScript
export function parseStringify(data: unknown) {
  if (typeof data === "string") {
    try {
      return JSON.parse(data);
    } catch (err: unknown) {
      if (err instanceof Error) {
        console.error("Error parsing JSON:", err.message);
      } else {
        console.error("Error parsing JSON: unknown error");
      }
      throw new Error("Failed to parse user data."); // Optional: throw an error if parsing fails
    }
  }
  return data; // Return data as is if already an object
}
TL;DR
 Developers encountered an error while creating a document in a course app using Node.js SDK in a Next.js project. The code includes a function to create a course document and a helper function called parseStringify. The error could be due to issues within the createCourse function or the parseStringify function.Recommended threads
- Internal server Error when trying to exe...
When executing the function locally it works fine, but when the function is deployed I get this error: ```requests.exceptions.HTTPError: 500 Server Error: Inter...
 - Dynamic Roles
I tried to store a row with this permissions: permissions.push( Permission.read(Role.users("verified")), Permission.write(Role.label(`c-${calend...
 - appwrite auth problem regarding the sess...
Hi, I have problem with auth. When I try to login/signup using OTP, at the end session.secret is empty, i have searched online and in the docs but i cannot find...