Skip to content

Commit

Permalink
fix: turning off api requests
Browse files Browse the repository at this point in the history
  • Loading branch information
moonbamijam committed Jan 23, 2024
1 parent 6545b1c commit 7968016
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 130 deletions.
78 changes: 39 additions & 39 deletions app/api/about/[id]/route.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import connectMongoDB from "@utilities/mongodb";
import About from "@models/about";
import { Params } from "next/dist/shared/lib/router/utils/route-matcher";
import { NextResponse } from "next/server";
// import connectMongoDB from "@utilities/mongodb";
// import About from "@models/about";
// 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,
name: name,
nickname: nickname,
age: age,
birthday: birthday,
sex: sex,
nationality: nationality,
status: status,
languages: languages
} = await request.json();
await connectMongoDB();
await About.findByIdAndUpdate(id, {
title,
desc,
name,
nickname,
age,
birthday,
sex,
nationality,
status,
languages
});
return NextResponse.json({ message: "Updated" }, { status: 200 });
}
// export async function PUT(request: Request, { params }: Params) {
// const { id } = params;
// const {
// title: title,
// desc: desc,
// name: name,
// nickname: nickname,
// age: age,
// birthday: birthday,
// sex: sex,
// nationality: nationality,
// status: status,
// languages: languages
// } = await request.json();
// await connectMongoDB();
// await About.findByIdAndUpdate(id, {
// title,
// desc,
// name,
// nickname,
// age,
// birthday,
// sex,
// nationality,
// status,
// languages
// });
// return NextResponse.json({ message: "Updated" }, { status: 200 });
// }

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

export async function POST(request: Request, response: Response) {
const {
title,
desc,
name,
nickname,
age,
birthday,
sex,
nationality,
status,
languages
} = await request.json();
await connectMongoDB();
await About.create({
title,
desc,
name,
nickname,
age,
birthday,
sex,
nationality,
status,
languages
});
};
// export async function POST(request: Request, response: Response) {
// const {
// title,
// desc,
// name,
// nickname,
// age,
// birthday,
// sex,
// nationality,
// status,
// languages
// } = await request.json();
// await connectMongoDB();
// await About.create({
// title,
// desc,
// name,
// nickname,
// age,
// birthday,
// sex,
// nationality,
// status,
// languages
// });
// };

export async function GET() {
await connectMongoDB();
const about = await About.find();
return NextResponse.json({ about })
};
// export async function GET() {
// await connectMongoDB();
// const about = await About.find();
// return NextResponse.json({ about })
// };
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 })
// };
18 changes: 9 additions & 9 deletions utilities/mongodb.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import mongoose from "mongoose";
// import mongoose from "mongoose";

const connectMongoDB = async () => {
try {
await mongoose.connect(process.env.MONGODB_URI as string);
} catch (error) {
console.log(error);
}
};
// const connectMongoDB = async () => {
// try {
// await mongoose.connect(process.env.MONGODB_URI as string);
// } catch (error) {
// console.log(error);
// }
// };

export default connectMongoDB;
// export default connectMongoDB;

0 comments on commit 7968016

Please sign in to comment.