Skip to content

Commit

Permalink
fix: turn on api for projects
Browse files Browse the repository at this point in the history
  • Loading branch information
moonbamijam committed Jan 23, 2024
1 parent 780854a commit e5e3660
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 47 deletions.
50 changes: 25 additions & 25 deletions app/api/projects/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
// import connectMongoDB from "@utilities/mongodb";
// import Project from "@models/project";
// import { Params } from "next/dist/shared/lib/router/utils/route-matcher";
// import { NextResponse } from "next/server";
import connectMongoDB from "@utilities/mongodb";
import Project from "@models/project";
import { Params } from "next/dist/shared/lib/router/utils/route-matcher";
import { NextResponse } from "next/server";

// export async function PUT(request: Request, { params }: Params) {
// const { id } = params;
// const {
// title: title,
// desc: desc,
// href: href,
// } = await request.json();
// await connectMongoDB();
// await Project.findByIdAndUpdate(id, {
// title,
// desc,
// href,
// });
// return NextResponse.json({ message: "Updated" }, { status: 200 });
// }
export async function PUT(request: Request, { params }: Params) {
const { id } = params;
const {
title: title,
desc: desc,
href: href,
} = await request.json();
await connectMongoDB();
await Project.findByIdAndUpdate(id, {
title,
desc,
href,
});
return NextResponse.json({ message: "Updated" }, { status: 200 });
}

// export async function GET(request: Request, { params }: Params ) {
// const { id } = params;
// await connectMongoDB();
// const projects = await Project.findOne({ _id: id });
// return NextResponse.json({ projects }, { status: 200 });
// };
export async function GET(request: Request, { params }: Params ) {
const { id } = params;
await connectMongoDB();
const projects = await Project.findOne({ _id: id });
return NextResponse.json({ projects }, { status: 200 });
};
44 changes: 22 additions & 22 deletions app/api/projects/route.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
// import connectMongoDB from "@utilities/mongodb";
// import Project from "@models/project";
// import { NextResponse } from "next/server";
import connectMongoDB from "@utilities/mongodb";
import Project from "@models/project";
import { NextResponse } from "next/server";

// export async function POST(request: Request, response: Response) {
// const {
// title,
// desc,
// href
// } = await request.json();
// await connectMongoDB();
// await Project.create({
// title,
// desc,
// href
// });
// return NextResponse.json({ status: 200 });
// };
export async function POST(request: Request, response: Response) {
const {
title,
desc,
href
} = await request.json();
await connectMongoDB();
await Project.create({
title,
desc,
href
});
return NextResponse.json({ status: 200 });
};

// export async function GET() {
// await connectMongoDB();
// const project = await Project.find();
// return NextResponse.json({ project })
// };
export async function GET() {
await connectMongoDB();
const project = await Project.find();
return NextResponse.json({ project })
};

0 comments on commit e5e3660

Please sign in to comment.