Skip to content

Commit 9b38563

Browse files
authored
Merge pull request #2 from lakshayg2005/auth-flow-fix
Storing python script generated data to supabase through seed.ts
2 parents 2689251 + c277e8d commit 9b38563

File tree

8 files changed

+795
-37
lines changed

8 files changed

+795
-37
lines changed

package-lock.json

Lines changed: 661 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"dev": "next dev",
77
"build": "next build",
88
"start": "next start",
9-
"lint": "next lint"
9+
"lint": "next lint",
10+
"seed": "ts-node src/lib/syncData.ts"
1011
},
1112
"dependencies": {
1213
"@headlessui/react": "^2.2.2",
@@ -76,6 +77,9 @@
7677
"zod": "^3.24.3"
7778
},
7879
"devDependencies": {
79-
"@types/crypto-js": "^4.2.2"
80+
"@types/crypto-js": "^4.2.2",
81+
"dotenv": "^17.0.1",
82+
"ts-node": "^10.9.2",
83+
"tsx": "^4.20.3"
8084
}
8185
}
File renamed without changes.
File renamed without changes.

src/lib/seed.ts

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import 'dotenv/config';
2+
import { supabase } from './supabase';
3+
import professors from './data/professors.json' assert { type: 'json' };
4+
import courses from './data/courses.json' assert { type: 'json' };
5+
6+
async function seedProfessors() {
7+
console.log('🌱 Seeding professors...');
8+
9+
for (const professor of professors) {
10+
const {
11+
id, // don't insert custom id
12+
education, // remove if not in table
13+
...rest
14+
} = professor;
15+
16+
const { error } = await supabase
17+
.from('professors')
18+
.upsert(
19+
{
20+
...rest,
21+
overall_rating: 0,
22+
knowledge_rating: 0,
23+
teaching_rating: 0,
24+
approachability_rating: 0,
25+
review_count: 0,
26+
},
27+
{ onConflict: 'email' } // uses email to deduplicate
28+
);
29+
30+
if (error) {
31+
console.error('❌ Error inserting professor:', error.message);
32+
}
33+
}
34+
}
35+
36+
async function seedCourses() {
37+
console.log('🌱 Seeding courses...');
38+
39+
const courseArray = Array.isArray(courses)
40+
? courses.flat()
41+
: Object.values(courses).flat();
42+
43+
console.log(
44+
'📦 courseArray preview:',
45+
courseArray.slice?.(0, 3) || Object.values(courseArray).slice(0, 3)
46+
);
47+
48+
for (const course of courseArray) {
49+
const { id, ...rest } = course;
50+
51+
const { error } = await supabase
52+
.from('courses')
53+
.upsert(
54+
{
55+
...rest,
56+
rating: 0,
57+
review_count: 0,
58+
},
59+
{ onConflict: 'code' } // assumes 'code' is unique for each course
60+
);
61+
62+
if (error) {
63+
console.error('❌ Error inserting course:', error.message);
64+
}
65+
}
66+
}
67+
68+
(async () => {
69+
console.log('⏳ Seeding data...');
70+
await seedProfessors();
71+
await seedCourses();
72+
console.log('✅ Seeding complete');
73+
})();

src/lib/supabase.ts

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,26 @@ if (!supabaseUrl || !supabaseAnonKey) {
1010

1111
export const supabase = createClient<Database>(supabaseUrl, supabaseAnonKey);
1212

13-
export const getCurrentUser = async () => {
14-
const { data: { session } } = await supabase.auth.getSession();
15-
return session?.user ?? null;
16-
};
17-
18-
export const getAnonymousId = async (): Promise<string | null> => {
19-
const user = await getCurrentUser();
20-
if (!user) return null;
13+
14+
15+
16+
17+
18+
// export const getCurrentUser = async () => {
19+
// const { data: { session } } = await supabase.auth.getSession();
20+
// return session?.user ?? null;
21+
// };
22+
23+
// export const getAnonymousId = async (): Promise<string | null> => {
24+
// const user = await getCurrentUser();
25+
// if (!user) return null;
2126

22-
const { data, error } = await supabase
23-
.from('users_auth')
24-
.select('anonymous_id')
25-
.eq('user_id', user.id)
26-
.single();
27+
// const { data, error } = await supabase
28+
// .from('users_auth')
29+
// .select('anonymous_id')
30+
// .eq('user_id', user.id)
31+
// .single();
2732

28-
if (error || !data) return null;
29-
return data.anonymous_id;
30-
};
33+
// if (error || !data) return null;
34+
// return data.anonymous_id;
35+
// };

src/types/index.ts

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
import { LucideIcon } from "lucide-react";
2+
export enum Grade {
3+
APlus = "A+",
4+
A = "A",
5+
B = "B",
6+
C = "C",
7+
D = "D",
8+
F = "F"
9+
}
210
export interface User {
311
id: string;
412
auth_id: string;
@@ -15,13 +23,15 @@ export interface Course {
1523
title: string;
1624
department: string;
1725
credits: number;
18-
overall_rating: number;
19-
difficulty_rating: number;
20-
workload_rating: number;
21-
review_count: number;
22-
created_at: Date;
23-
updated_at: Date;
24-
26+
overall_rating: number; // default: 0
27+
difficulty_rating: number; // default: 0
28+
workload_rating: number; // default: 0
29+
review_count: number; // default: 0
30+
created_at: Date;
31+
updated_at: Date;
32+
33+
// Optional grade for future use (e.g., average grade given)
34+
grade?: Grade;
2535
}
2636

2737
export interface Professor {
@@ -30,19 +40,21 @@ export interface Professor {
3040
post: string;
3141
email: string;
3242
department: string;
33-
avatar_url: string;
34-
website: string | null;
35-
overall_rating: number;
36-
knowledge_rating: number;
37-
teaching_rating: number;
38-
approachability_rating: number;
39-
review_count: number;
43+
avatar_url: string;
44+
website: string | null;
45+
overall_rating: number; // default: 0
46+
knowledge_rating: number; // default: 0
47+
teaching_rating: number; // default: 0
48+
approachability_rating: number;// default: 0
49+
review_count: number; // default: 0
4050
research_interests: string[];
41-
created_at: Date;
42-
updated_at: Date;
43-
51+
created_at: Date;
52+
updated_at: Date;
53+
54+
grade?: Grade; // optional for consistency
4455
}
4556

57+
4658
export interface ProfessorCourse {
4759
professor_id: string;
4860
course_id: string;

tsconfig.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"compilerOptions": {
3-
"target": "es5",
3+
"target": "ES2020",
44
"lib": ["dom", "dom.iterable", "esnext"],
55
"allowJs": true,
66
"skipLibCheck": true,
@@ -22,6 +22,10 @@
2222
"@/*": ["./src/*"]
2323
}
2424
},
25+
"ts-node": {
26+
"esm": true,
27+
"experimentalSpecifierResolution": "node"
28+
},
2529
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
2630
"exclude": ["node_modules"]
2731
}

0 commit comments

Comments
 (0)