Skip to content

Commit dc11ee0

Browse files
committed
updated judge specialties in migrations & seeding
1 parent 485000e commit dc11ee0

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

migrations/create-users.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import tracks from '../app/(api)/_data/tracks.json' assert { type: 'json' };
2+
3+
const domains = [...new Set(tracks.map((track) => track.type))];
4+
15
export async function up(db) {
26
await db.createCollection('users', {
37
validator: {
@@ -30,8 +34,10 @@ export async function up(db) {
3034
specialties: {
3135
bsonType: 'array',
3236
description: 'specialties must be an array of valid string values',
37+
maxItems: domains.length,
38+
minItems: domains.length,
3339
items: {
34-
enum: ['tech', 'business', 'design'],
40+
enum: domains,
3541
description: 'specialty must be either tech, business, or design',
3642
},
3743
},

scripts/generateData.mjs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@ import { faker } from '@faker-js/faker';
22
import { ObjectId } from 'mongodb';
33
import tracks from '../app/(api)/_data/tracks.json' assert { type: 'json' };
44

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+
517
function generateData(collectionName, numDocuments) {
6-
const specialties = ['tech', 'business', 'design'];
7-
const numSpecialties = 2;
18+
const specialties = [...new Set(tracks.map((track) => track.type))];
819
const hackerPositions = ['developer', 'designer', 'pm', 'other'];
920
const eventTypes = ['workshop', 'meal', 'general', 'activity'];
1021

@@ -15,7 +26,7 @@ function generateData(collectionName, numDocuments) {
1526
name: faker.person.fullName(),
1627
email: faker.internet.email(),
1728
password: faker.internet.password(),
18-
specialties: faker.helpers.arrayElements(specialties, numSpecialties),
29+
specialties: shuffleSpecialties(specialties),
1930
role: 'judge',
2031
}));
2132

0 commit comments

Comments
 (0)