|
| 1 | +import { writeFileSync } from "fs"; |
| 2 | +import { v4 as uuidv4 } from "uuid"; |
| 3 | +import applist from "./applicationlist.json"; |
| 4 | + |
| 5 | +const convertTimesApplied = { |
| 6 | + "This is my first time!": 0, |
| 7 | + Once: 1, |
| 8 | + Twice: 2, |
| 9 | + "3 or more": 3, |
| 10 | +}; |
| 11 | + |
| 12 | +const createFullList = () => { |
| 13 | + const seededData = applist.map((currApplication) => { |
| 14 | + const { id } = currApplication || uuidv4(); |
| 15 | + |
| 16 | + return { |
| 17 | + id, |
| 18 | + academicOrCoop: currApplication.academicOrCoop, |
| 19 | + academicYear: currApplication.academicYear, |
| 20 | + email: currApplication.email, |
| 21 | + firstChoiceRole: currApplication.firstChoiceRole, |
| 22 | + secondChoiceRole: currApplication.secondChoiceRole, |
| 23 | + firstName: currApplication.firstName, |
| 24 | + lastName: currApplication.lastName, |
| 25 | + heardFrom: currApplication.heardFrom, |
| 26 | + locationPreference: currApplication.locationPreference, |
| 27 | + program: currApplication.program, |
| 28 | + pronouns: currApplication.pronouns, |
| 29 | + resumeUrl: currApplication.resumeUrl, |
| 30 | + timesApplied: convertTimesApplied[currApplication.timesApplied], |
| 31 | + shortAnswerQuestions: currApplication.shortAnswerQuestions |
| 32 | + ? currApplication.shortAnswerQuestions.map((q) => JSON.stringify(q)) |
| 33 | + : [], |
| 34 | + roleSpecificQuestions: currApplication.roleSpecificQuestions |
| 35 | + ? currApplication.roleSpecificQuestions.map((q) => ({ |
| 36 | + role: q.role, |
| 37 | + questions: q.questions |
| 38 | + ? q.questions.map((question) => JSON.stringify(question)) |
| 39 | + : [], |
| 40 | + })) |
| 41 | + : [], |
| 42 | + term: currApplication.term, |
| 43 | + status: currApplication.status, |
| 44 | + submittedAt: new Date(currApplication.timestamp).toISOString(), |
| 45 | + createdAt: new Date(), |
| 46 | + updatedAt: new Date(), |
| 47 | + }; |
| 48 | + }); |
| 49 | + |
| 50 | + return seededData; |
| 51 | +}; |
| 52 | + |
| 53 | +// const createApplicantRecords = (records) => { |
| 54 | +// const output = []; |
| 55 | + |
| 56 | +// records.forEach((record) => { |
| 57 | +// const applicantId = record.id; |
| 58 | + |
| 59 | +// if (record.firstChoiceRole) { |
| 60 | +// const roleSpecificQs = |
| 61 | +// record.roleSpecificQuestions |
| 62 | +// ?.filter((q) => q.role === record.firstChoiceRole) |
| 63 | +// ?.flatMap( |
| 64 | +// (q) => |
| 65 | +// q.questions?.map((question) => JSON.stringify(question)) || [], |
| 66 | +// ) || []; |
| 67 | + |
| 68 | +// output.push({ |
| 69 | +// id: uuidv4(), |
| 70 | +// applicantId, |
| 71 | +// position: record.firstChoiceRole, // Changed from 'role' to 'position' to match migration |
| 72 | +// roleSpecificQuestions: roleSpecificQs, |
| 73 | +// choice: 1, |
| 74 | +// status: record.status || "Applied", |
| 75 | +// skillCategory: null, |
| 76 | +// extraInfo: { |
| 77 | +// // Added extraInfo field from migration |
| 78 | +// notes: "", |
| 79 | +// interviewNotes: "", |
| 80 | +// interviewers: [], |
| 81 | +// }, |
| 82 | +// createdAt: new Date(), |
| 83 | +// updatedAt: new Date(), |
| 84 | +// }); |
| 85 | +// } |
| 86 | + |
| 87 | +// // Add second choice record if it exists |
| 88 | +// if (record.secondChoiceRole) { |
| 89 | +// const roleSpecificQs = |
| 90 | +// record.roleSpecificQuestions |
| 91 | +// ?.filter((q) => q.role === record.secondChoiceRole) |
| 92 | +// ?.flatMap( |
| 93 | +// (q) => |
| 94 | +// q.questions?.map((question) => JSON.stringify(question)) || [], |
| 95 | +// ) || []; |
| 96 | + |
| 97 | +// output.push({ |
| 98 | +// id: uuidv4(), |
| 99 | +// applicantId, |
| 100 | +// position: record.secondChoiceRole, // Changed from 'role' to 'position' |
| 101 | +// roleSpecificQuestions: roleSpecificQs, |
| 102 | +// choice: 2, |
| 103 | +// status: record.secondChoiceStatus || "Applied", |
| 104 | +// skillCategory: null, |
| 105 | +// extraInfo: { |
| 106 | +// // Added extraInfo field |
| 107 | +// notes: "", |
| 108 | +// interviewNotes: "", |
| 109 | +// interviewers: [], |
| 110 | +// }, |
| 111 | +// createdAt: new Date(), |
| 112 | +// updatedAt: new Date(), |
| 113 | +// }); |
| 114 | +// } |
| 115 | +// }); |
| 116 | + |
| 117 | +// return output; |
| 118 | +// }; |
| 119 | + |
| 120 | +const main = () => { |
| 121 | + // const full_list = createFullList(); |
| 122 | + // const applicantRecords = createApplicantRecords(applicants); // Pass applicants to the function |
| 123 | + // // Write applicants to a separate JSON file |
| 124 | + // writeFileSync("./seed-applicants.json", JSON.stringify(applicants, null, 2)); |
| 125 | + // // Write applicant records to a separate JSON file |
| 126 | + // writeFileSync( |
| 127 | + // "./seed-applicant-records.json", |
| 128 | + // JSON.stringify(applicantRecords, null, 2), |
| 129 | + // ); |
| 130 | + // console.log( |
| 131 | + // `Generated ${applicants.length} applicants and ${applicantRecords.length} applicant records.`, |
| 132 | + // ); |
| 133 | +}; |
| 134 | + |
| 135 | +// Run the main function |
| 136 | +main(); |
0 commit comments