(stepNum: number)
| 32 | } |
| 33 | |
| 34 | async function insertStep(stepNum: number): Promise<void> { |
| 35 | if (stepNum < 1) { |
| 36 | throw Error('Step not inserted. New step number must be greater than 0.'); |
| 37 | } |
| 38 | const challengeOrder = getMetaData().challengeOrder; |
| 39 | |
| 40 | if (stepNum > challengeOrder.length + 1) |
| 41 | throw Error( |
| 42 | `Step not inserted. New step number must be less than ${ |
| 43 | challengeOrder.length + 2 |
| 44 | }.` |
| 45 | ); |
| 46 | |
| 47 | const previousChallenge = |
| 48 | stepNum > 1 ? getChallenge(challengeOrder[stepNum - 2].id) : null; |
| 49 | const nextChallenge = |
| 50 | stepNum <= challengeOrder.length |
| 51 | ? getChallenge(challengeOrder[stepNum - 1].id) |
| 52 | : null; |
| 53 | |
| 54 | const challengeSeeds = previousChallenge?.challengeFiles ?? []; |
| 55 | const challengeType = |
| 56 | previousChallenge?.challengeType ?? nextChallenge?.challengeType; |
| 57 | |
| 58 | const challengeId = new ObjectId(); |
| 59 | |
| 60 | createStepFile({ |
| 61 | challengeId, |
| 62 | stepNum, |
| 63 | challengeType, |
| 64 | challengeSeeds |
| 65 | }); |
| 66 | |
| 67 | await insertStepIntoMeta({ stepNum, stepId: challengeId }); |
| 68 | updateStepTitles(); |
| 69 | console.log(`Successfully inserted new step #${stepNum}`); |
| 70 | } |
| 71 | |
| 72 | async function createEmptySteps(num: number): Promise<void> { |
| 73 | if (num < 1 || num > 1000) { |
no test coverage detected