@@ -4,46 +4,94 @@ import tracks from '../app/(api)/_data/tracks.json' assert { type: 'json' };
4
4
5
5
function generateData ( collectionName , numDocuments ) {
6
6
const specialties = [ 'tech' , 'business' , 'design' ] ;
7
- const fakeTracks = Array . from (
8
- { length : Math . ceil ( Math . random ( ) * 5 ) } ,
9
- ( ) => tracks [ Math . floor ( Math . random ( ) * tracks . length ) ] . name
10
- ) ;
7
+ const numSpecialties = 2 ;
8
+ const hackerPositions = [ 'developer' , 'designer' , 'pm' , 'other' ] ;
9
+ const eventTypes = [ 'workshop' , 'meal' , 'general' , 'activity' ] ;
11
10
12
11
let data = [ ] ;
13
- if ( collectionName === 'judges' ) {
14
- data = Array . from ( { length : numDocuments } , ( ) => ( {
15
- name : faker . person . firstName ( ) ,
12
+
13
+ if ( collectionName === 'users' ) {
14
+ const judges = Array . from ( { length : numDocuments } , ( ) => ( {
15
+ name : faker . person . fullName ( ) ,
16
16
email : faker . internet . email ( ) ,
17
17
password : faker . internet . password ( ) ,
18
- specialty : specialties [ Math . floor ( Math . random ( ) * specialties . length ) ] ,
19
- judge_group_id : new ObjectId ( ) ,
18
+ specialties : faker . helpers . arrayElements ( specialties , numSpecialties ) ,
20
19
role : 'judge' ,
21
20
} ) ) ;
21
+
22
+ const hackers = Array . from ( { length : numDocuments } , ( ) => ( {
23
+ name : faker . person . firstName ( ) ,
24
+ email : faker . internet . email ( ) ,
25
+ password : faker . internet . password ( ) ,
26
+ position : faker . helpers . arrayElement ( hackerPositions ) ,
27
+ is_beginner : faker . datatype . boolean ( ) ,
28
+ starter_kit_stage : faker . number . int ( { min : 1 , max : 4 } ) ,
29
+ role : 'hacker' ,
30
+ } ) ) ;
31
+
32
+ data = [ ...judges , ...hackers ] ;
22
33
} else if ( collectionName === 'admin' ) {
23
34
data . push ( {
24
35
name : 'Admin' ,
25
36
email : 'admin@hackdavis.io' ,
26
37
password : '$2a$10$oit1hC4hBaj9OX.WQxm3uOtb0qnPNk4iR9QhZmFm7/r1rAphAMAva' ,
27
- specialty : 'tech' ,
28
38
role : 'admin' ,
29
39
} ) ;
30
40
} else if ( collectionName === 'teams' ) {
31
41
data = Array . from ( { length : numDocuments } , ( ) => ( {
32
42
number : faker . number . int ( { min : 1 , max : 1000 } ) ,
33
43
name : faker . lorem . word ( ) ,
34
- tracks : fakeTracks ,
44
+ tracks : faker . helpers . arrayElements (
45
+ tracks . map ( ( t ) => t . name ) ,
46
+ faker . number . int ( { min : 1 , max : 5 } )
47
+ ) ,
35
48
} ) ) ;
36
49
} else if ( collectionName === 'submissions' ) {
37
- data = Array . from ( { length : numDocuments } , ( ) => ( {
38
- judge_id : new ObjectId ( ) ,
39
- team_id : new ObjectId ( ) ,
40
- scores : Array . from ( { length : 5 } , ( ) => Math . ceil ( Math . random ( ) * 5 ) ) ,
41
- correlations : Array . from ( fakeTracks , ( fakeTrack ) => ( {
42
- track : fakeTrack ,
43
- score : Math . ceil ( Math . random ( ) * 5 ) ,
44
- } ) ) ,
45
- comments : faker . lorem . sentence ( ) ,
46
- } ) ) ;
50
+ data = Array . from ( { length : numDocuments } , ( ) => {
51
+ const scores = {
52
+ social_good : faker . number . int ( { min : 1 , max : 5 } ) ,
53
+ creativity : faker . number . int ( { min : 1 , max : 5 } ) ,
54
+ presentation : faker . number . int ( { min : 1 , max : 5 } ) ,
55
+ comments : faker . lorem . sentence ( ) ,
56
+ } ;
57
+ const randomTracks = faker . helpers . arrayElements (
58
+ tracks . map ( ( t ) => t . name ) ,
59
+ faker . number . int ( { min : 1 , max : 5 } )
60
+ ) ;
61
+ randomTracks . map ( ( t ) => {
62
+ scores [ t ] = Array . from ( { length : 5 } , ( ) =>
63
+ faker . number . int ( { min : 1 , max : 5 } )
64
+ ) ;
65
+ } ) ;
66
+
67
+ return {
68
+ judge_id : new ObjectId ( ) ,
69
+ team_id : new ObjectId ( ) ,
70
+ scores : scores ,
71
+ is_scored : faker . datatype . boolean ( ) ,
72
+ } ;
73
+ } ) ;
74
+ } else if ( collectionName === 'events' ) {
75
+ data = Array . from ( { length : numDocuments } , ( ) => {
76
+ const eventType = faker . helpers . arrayElement ( eventTypes ) ;
77
+ const isWorkshop = eventType === 'workshop' ;
78
+ const startTime = faker . date . between ( {
79
+ from : '2025-04-19T00:00:00.000Z' ,
80
+ to : '2025-04-20T23:59:59.999Z' ,
81
+ } ) ;
82
+
83
+ return {
84
+ name : faker . company . catchPhrase ( ) ,
85
+ type : eventType ,
86
+ host : isWorkshop ? faker . company . name ( ) : '' ,
87
+ location : faker . location . street ( ) ,
88
+ start_time : startTime ,
89
+ end_time : faker . date . soon ( { days : 2 , refDate : startTime } ) ,
90
+ tags : isWorkshop
91
+ ? faker . helpers . arrayElements ( hackerPositions , { min : 1 } )
92
+ : [ ] ,
93
+ } ;
94
+ } ) ;
47
95
}
48
96
49
97
return data ;
0 commit comments