Skip to content

Commit b91a389

Browse files
committed
fix: fetch api display project details
1 parent 7417ec1 commit b91a389

File tree

4 files changed

+269
-247
lines changed

4 files changed

+269
-247
lines changed

src/app/api/project/route.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export async function GET(req) {
1010
const url = new URL(req.url);
1111
const pathWithNamespace = url.searchParams.get("pathWithNamespace");
1212
const userId = url.searchParams.get("userId");
13+
const projectId = url.searchParams.get("projectId");
1314

1415
let query = {};
1516

@@ -21,6 +22,10 @@ export async function GET(req) {
2122
query.userId = userId;
2223
}
2324

25+
if (projectId) {
26+
query._id = projectId;
27+
}
28+
2429
const projects = await Project.find(query);
2530

2631
return NextResponse.json(projects, { status: 200 });
@@ -120,6 +125,9 @@ export async function DELETE(req) {
120125

121126
export async function PUT(req) {
122127
const { projectid, ...updates } = await req.json(); // Destructure the project JSON
128+
console.log(projectid, updates);
129+
// Connect to MongoDB
130+
await connectMongoDB();
123131

124132
// Check if there is a valid `projectid` and update fields are not empty
125133
if (!projectid || Object.keys(updates).length === 0) {
@@ -129,9 +137,6 @@ export async function PUT(req) {
129137
);
130138
}
131139

132-
// Connect to MongoDB
133-
await connectMongoDB();
134-
135140
// Perform the update
136141
const updatedProjects = await Project.updateMany(
137142
{ projectid },
@@ -142,4 +147,4 @@ export async function PUT(req) {
142147
{ message: "Successfully updated requests", updatedProjects },
143148
{ status: 200 }
144149
);
145-
}
150+
}

src/app/api/request/route.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ export async function POST(req) {
4848
export async function PUT(req) {
4949
const { projectid, ...updates } = await req.json(); // Destructure the request JSON
5050

51+
// Connect to MongoDB
52+
await connectMongoDB();
53+
5154
// Check if there is a valid `projectid` and update fields are not empty
5255
if (!projectid || Object.keys(updates).length === 0) {
5356
return NextResponse.json(
@@ -56,9 +59,6 @@ export async function PUT(req) {
5659
);
5760
}
5861

59-
// Connect to MongoDB
60-
await connectMongoDB();
61-
6262
// Perform the update
6363
const updatedRequests = await Request.updateMany(
6464
{ projectid },

src/app/project/[requestId]/page.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export default function Projectdetails() {
4646
}
4747

4848
const data = await res.json();
49-
49+
console.log(data);
5050
if (data.length > 0) {
5151
const project = data[0];
5252
setProjectDetails({
@@ -93,7 +93,7 @@ export default function Projectdetails() {
9393

9494
const fetchResource = async () => {
9595
try {
96-
const res = await fetch(`/api/resource/?requestId=${requestId}`, {
96+
const res = await fetch(`/api/resource/?projectRequest=${requestId}`, {
9797
method: "GET",
9898
headers: { "Content-Type": "application/json" },
9999
});
@@ -276,7 +276,7 @@ export default function Projectdetails() {
276276
<p className="text-lg font-normal ml-16 mt-2">{projectDetails.lastUpdate}</p>
277277
</div> */}
278278
<div>
279-
<p className="text-xl font-medium mx-16 mt-5">Create By</p>
279+
<p className="text-xl font-medium mx-16 mt-5">Created By</p>
280280
<p className="text-lg font-normal ml-16 mt-2">
281281
{projectDetails.pathWithNamespace}
282282
</p>

0 commit comments

Comments
 (0)