Skip to content

Commit d953f65

Browse files
committed
successfully build
1 parent 64709bd commit d953f65

File tree

5 files changed

+53
-108
lines changed

5 files changed

+53
-108
lines changed

app/api/profile-projects/route.ts

Lines changed: 12 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,3 @@
1-
// // app/api/profile-projects/route.ts
2-
// import { NextRequest, NextResponse } from 'next/server';
3-
// import { db } from '@/lib/db';
4-
// import { projects } from '@/lib/schema';
5-
// import { eq } from 'drizzle-orm';
6-
// import { adminAuth } from '@/lib/firebase/firebaseadmin';
7-
8-
// export async function GET(req: NextRequest) {
9-
// try {
10-
// const authHeader = req.headers.get("authorization");
11-
// const token = authHeader?.split("Bearer ")[1];
12-
13-
// if (!token) {
14-
// return NextResponse.json({ error: "Unauthorized - No token" }, { status: 401 });
15-
// }
16-
17-
// const decodedToken = await adminAuth.verifyIdToken(token);
18-
// const firebaseUid = decodedToken.uid;
19-
20-
// const userProjects = await db
21-
// .select()
22-
// .from(projects)
23-
// .where(eq(projects.createdByUid, firebaseUid));
24-
25-
// return NextResponse.json(userProjects);
26-
// } catch (err) {
27-
// console.error("Error in /api/profile-projects:", err);
28-
// return NextResponse.json({ error: "Server error" }, { status: 500 });
29-
// }
30-
// }
31-
32-
33-
// app/api/profile-projects/route.ts
34-
// import { NextRequest, NextResponse } from 'next/server';
35-
// import { db } from '@/lib/db';
36-
// import { eq } from 'drizzle-orm';
37-
// import { adminAuth } from '@/lib/firebase/firebaseadmin';
38-
// import { projects } from '@/lib/schema';
39-
40-
// export async function GET(req: NextRequest) {
41-
// try {
42-
// const authHeader = req.headers.get("authorization");
43-
// const token = authHeader?.split("Bearer ")[1];
44-
45-
// if (!token) {
46-
// return NextResponse.json({ error: "Unauthorized - No token" }, { status: 401 });
47-
// }
48-
49-
// const decodedToken = await adminAuth.verifyIdToken(token);
50-
// const firebaseUid = decodedToken.uid;
51-
52-
// const userProjects = await db.query.projects.findMany({
53-
// where: (fields, { eq }) => eq(fields.createdByUid, firebaseUid),
54-
// with: {
55-
// categories: {
56-
// with: {
57-
// category: true,
58-
// optionValue: true,
59-
// },
60-
// },
61-
// members: true,
62-
// },
63-
// });
64-
65-
// // Transform the result to include flattened category structure
66-
// const result = userProjects.map((project) => ({
67-
// projectId: project.projectId,
68-
// projectName: project.projectName,
69-
// projectDescription: project.projectDescription,
70-
// projectLink: project.projectLink,
71-
// customDomain: project.customDomain,
72-
// createdAt: project.createdAt,
73-
// members: project.members,
74-
// categories: project.categories.map((cat) => ({
75-
// categoryName: cat.category.categoryName,
76-
// optionName: cat.optionValue.optionName,
77-
// })),
78-
// }));
79-
80-
// return NextResponse.json(result);
81-
// } catch (err) {
82-
// console.error("Error in /api/profile-projects:", err);
83-
// return NextResponse.json({ error: "Server error" }, { status: 500 });
84-
// }
85-
// }
86-
871

882
// app/api/profile-projects/route.ts
893
import { NextRequest, NextResponse } from 'next/server';
@@ -129,8 +43,18 @@ export async function GET(req: NextRequest) {
12943
.where(eq(projectOptions.projectId, project.projectId));
13044

13145
const categoriesArray = await Promise.all(projectOpts.map(async (opt) => {
132-
const cat = await db.select({ categoryName: categories.category }).from(categories).where(eq(categories.categoryId, opt.categoryId));
133-
const val = await db.select({ optionName: categoryOptionValues.optionName }).from(categoryOptionValues).where(eq(categoryOptionValues.optionId, opt.optionId));
46+
47+
if (opt.categoryId === null || opt.optionId === null) return null;
48+
49+
const cat = await db
50+
.select({ categoryName: categories.category })
51+
.from(categories)
52+
.where(eq(categories.categoryId, opt.categoryId));
53+
54+
const val = await db
55+
.select({ optionName: categoryOptionValues.optionName })
56+
.from(categoryOptionValues)
57+
.where(eq(categoryOptionValues.optionId, opt.optionId));
13458

13559
return cat.length && val.length ? {
13660
categoryName: cat[0].categoryName!,
Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
// File: app/api/projects/[projectId]/route.ts
2-
31
import { NextRequest } from "next/server";
42
import { db } from "@/lib/db";
53
import { eq } from "drizzle-orm";
6-
import { auth } from "@/lib/firebase/config"; // if you verify auth in API, else skip this
74
import {
85
projects,
96
teamMembers,
@@ -14,27 +11,33 @@ import {
1411

1512
export async function GET(
1613
req: NextRequest,
17-
{ params }: { params: { projectId: string } }
14+
context: { params: Promise<{ projectId: string }> }
1815
) {
19-
const projectId = Number(params.projectId);
20-
if (isNaN(projectId)) {
21-
return new Response(JSON.stringify({ error: "Invalid project ID" }), { status: 400 });
16+
const { projectId } = await context.params;
17+
const numericId = Number(projectId);
18+
19+
if (isNaN(numericId)) {
20+
return new Response(JSON.stringify({ error: "Invalid project ID" }), {
21+
status: 400,
22+
});
2223
}
2324

2425
try {
2526
const [projectData] = await db
2627
.select()
2728
.from(projects)
28-
.where(eq(projects.projectId, projectId));
29+
.where(eq(projects.projectId, numericId));
2930

3031
if (!projectData) {
31-
return new Response(JSON.stringify({ error: "Project not found" }), { status: 404 });
32+
return new Response(JSON.stringify({ error: "Project not found" }), {
33+
status: 404,
34+
});
3235
}
3336

3437
const members = await db
3538
.select({ name: teamMembers.name, linkedin: teamMembers.linkedin })
3639
.from(teamMembers)
37-
.where(eq(teamMembers.projectId, projectId));
40+
.where(eq(teamMembers.projectId, numericId));
3841

3942
const categoryOptions = await db
4043
.select({
@@ -47,18 +50,23 @@ export async function GET(
4750
categoryOptionValues,
4851
eq(projectOptions.optionId, categoryOptionValues.optionId)
4952
)
50-
.where(eq(projectOptions.projectId, projectId));
53+
.where(eq(projectOptions.projectId, numericId));
5154

5255
return new Response(
5356
JSON.stringify({
5457
...projectData,
5558
members,
5659
categories: categoryOptions,
5760
}),
58-
{ status: 200 }
61+
{
62+
status: 200,
63+
headers: { "Content-Type": "application/json" },
64+
}
5965
);
6066
} catch (err) {
6167
console.error("Error fetching project:", err);
62-
return new Response(JSON.stringify({ error: "Internal server error" }), { status: 500 });
68+
return new Response(JSON.stringify({ error: "Internal server error" }), {
69+
status: 500,
70+
});
6371
}
6472
}

app/edit/[projectId]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { useEffect, useState } from "react";
44
import { useParams, useRouter } from "next/navigation";
5-
import { Category, Project } from "@/types";
5+
import { Category, Project } from "@/types/project";
66
import { auth } from "@/lib/firebase/config";
77
import { onAuthStateChanged } from "firebase/auth";
88
import { ArrowLeft } from "lucide-react";

lib/firebase/auth.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Import User and other necessary types/functions from Firebase Auth
2-
import { signInWithPopup, GoogleAuthProvider, User, UserCredential } from 'firebase/auth';
2+
import { signInWithPopup, GoogleAuthProvider, User, UserCredential , getAuth } from 'firebase/auth';
33
import { doc, getDoc } from 'firebase/firestore';
44
import { auth, firestore } from './config'; // Ensure you are correctly importing from your Firebase config
55

@@ -9,7 +9,7 @@ export function onAuthStateChanged(callback: (authUser: User | null) => void) {
99
}
1010

1111
// Function for Google sign-in and role check
12-
export async function signInWithGoogle(): Promise<{ isAdmin: boolean }> {
12+
export async function signInWithGoogle(): Promise<{ user:User; isAdmin: boolean }> {
1313
const provider = new GoogleAuthProvider();
1414
provider.setCustomParameters({ display: "popup" }); // Force popup
1515

@@ -38,7 +38,7 @@ if (user.email !== adminOverrideEmail && !allowedEmailPattern.test(user.email))
3838

3939
const isAdmin = userDoc.exists() && userDoc.data()?.role === 'admin';
4040

41-
return { isAdmin };
41+
return {user, isAdmin };
4242
} catch (error) {
4343
console.error('Error signing in with Google:', error);
4444
throw error;

types/project.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,21 @@ export interface Project {
44
projectDescription: string;
55
projectLink: string;
66
members?: { name: string; linkedin: string }[];
7-
createdAt: string; // Ensure createdAt exists as a string (ISO format)
8-
customDomain?: string; // Re-adding customDomain field
9-
// New generic categories structure
7+
createdAt: string;
8+
customDomain?: string;
109
categories?: { categoryName: string; optionName: string }[];
10+
11+
// ✅ Add this to fix the "any" error in edit page
12+
selectedCategoryOptions: Record<string, string>;
13+
}
14+
15+
export interface CategoryOption {
16+
optionId: number;
17+
optionName: string;
18+
}
19+
20+
export interface Category {
21+
categoryId: number;
22+
categoryName: string;
23+
options: CategoryOption[];
1124
}

0 commit comments

Comments
 (0)