Skip to content

Commit

Permalink
updated judge specialties in migrations & seeding (#174)
Browse files Browse the repository at this point in the history
  • Loading branch information
JayJ104 authored Jan 21, 2025
1 parent bd72e07 commit 95b4e4b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
8 changes: 7 additions & 1 deletion migrations/create-users.mjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import tracks from '../app/(api)/_data/tracks.json' assert { type: 'json' };

const domains = [...new Set(tracks.map((track) => track.type))];

export async function up(db) {
await db.createCollection('users', {
validator: {
Expand Down Expand Up @@ -30,8 +34,10 @@ export async function up(db) {
specialties: {
bsonType: 'array',
description: 'specialties must be an array of valid string values',
maxItems: domains.length,
minItems: domains.length,
items: {
enum: ['tech', 'business', 'design'],
enum: domains,
description: 'specialty must be either tech, business, or design',
},
},
Expand Down
17 changes: 14 additions & 3 deletions scripts/generateData.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@ import { faker } from '@faker-js/faker';
import { ObjectId } from 'mongodb';
import tracks from '../app/(api)/_data/tracks.json' assert { type: 'json' };

function shuffleSpecialties(specialties) {
const shuffledSpecialties = [...specialties];
for (let i = shuffledSpecialties.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[shuffledSpecialties[i], shuffledSpecialties[j]] = [
shuffledSpecialties[j],
shuffledSpecialties[i],
];
}
return shuffledSpecialties;
}

function generateData(collectionName, numDocuments) {
const specialties = ['tech', 'business', 'design'];
const numSpecialties = 2;
const specialties = [...new Set(tracks.map((track) => track.type))];
const hackerPositions = ['developer', 'designer', 'pm', 'other'];
const eventTypes = ['workshop', 'meal', 'general', 'activity'];

Expand All @@ -15,7 +26,7 @@ function generateData(collectionName, numDocuments) {
name: faker.person.fullName(),
email: faker.internet.email(),
password: faker.internet.password(),
specialties: faker.helpers.arrayElements(specialties, numSpecialties),
specialties: shuffleSpecialties(specialties),
role: 'judge',
}));

Expand Down

0 comments on commit 95b4e4b

Please sign in to comment.