@@ -2,9 +2,20 @@ import { faker } from '@faker-js/faker';
2
2
import { ObjectId } from 'mongodb' ;
3
3
import tracks from '../app/(api)/_data/tracks.json' assert { type : 'json ' } ;
4
4
5
+ function shuffleSpecialties ( specialties ) {
6
+ const shuffledSpecialties = [ ...specialties ] ;
7
+ for ( let i = shuffledSpecialties . length - 1 ; i > 0 ; i -- ) {
8
+ const j = Math . floor ( Math . random ( ) * ( i + 1 ) ) ;
9
+ [ shuffledSpecialties [ i ] , shuffledSpecialties [ j ] ] = [
10
+ shuffledSpecialties [ j ] ,
11
+ shuffledSpecialties [ i ] ,
12
+ ] ;
13
+ }
14
+ return shuffledSpecialties ;
15
+ }
16
+
5
17
function generateData ( collectionName , numDocuments ) {
6
- const specialties = [ 'tech' , 'business' , 'design' ] ;
7
- const numSpecialties = 2 ;
18
+ const specialties = [ ...new Set ( tracks . map ( ( track ) => track . type ) ) ] ;
8
19
const hackerPositions = [ 'developer' , 'designer' , 'pm' , 'other' ] ;
9
20
const eventTypes = [ 'workshop' , 'meal' , 'general' , 'activity' ] ;
10
21
@@ -15,7 +26,7 @@ function generateData(collectionName, numDocuments) {
15
26
name : faker . person . fullName ( ) ,
16
27
email : faker . internet . email ( ) ,
17
28
password : faker . internet . password ( ) ,
18
- specialties : faker . helpers . arrayElements ( specialties , numSpecialties ) ,
29
+ specialties : shuffleSpecialties ( specialties ) ,
19
30
role : 'judge' ,
20
31
} ) ) ;
21
32
0 commit comments