Skip to content

Commit

Permalink
connect to db before fetching book details
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnMwendwa committed Oct 22, 2023
1 parent 4ba9ac7 commit cfa9348
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/pages/admin/[id]/edit.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import type { GetServerSideProps } from "next";
import { useRouter } from "next/router";
import Book from "lib/db/models/book_model";
import { Types } from "mongoose";

import EditBookForm, { EditBookFormProps } from "components/EditBookForm";
import connectDB from "lib/db/connection";

const EditPage = (props: EditBookFormProps) => {
const router = useRouter();
Expand Down Expand Up @@ -38,6 +38,8 @@ export const getServerSideProps: GetServerSideProps = async (contx) => {
},
};
}

await connectDB();
const bookData = await Book.findById(id);

if (!bookData) {
Expand Down

0 comments on commit cfa9348

Please sign in to comment.