@@ -7,7 +7,6 @@ import { delay, State } from "./index";
77 * @param id {string} - is the friendly name of the unit.
88 * @param name {string} - is the display name of the unit.
99 * @param lessons {Record<string, object>} - is the lessons map for the unit.
10- * @param key {string} - is the API key used to upload items.
1110 */
1211export async function handleUnit (
1312 state : State ,
@@ -17,14 +16,13 @@ export async function handleUnit(
1716 string ,
1817 { next : string [ ] ; previous : string [ ] ; requireAll ?: boolean }
1918 > ,
20- key : string ,
2119) : Promise < void > {
2220 // First, we need to figure out what the actual ID of our unit is.
2321 // If there isn't one, we'll just set it to null.
2422 const actualID : string | null = await axios
2523 . get ( "https://cratecode.com/internal/api/id/" + id , {
2624 headers : {
27- authorization : key ,
25+ authorization : state . key ,
2826 } ,
2927 } )
3028 . then ( ( res ) => res . data . id )
@@ -41,13 +39,13 @@ export async function handleUnit(
4139 { next : string [ ] ; previous : string [ ] ; requireAll : boolean }
4240 > = { } ;
4341
44- for ( const key in lessons ) {
42+ for ( const lessonID in lessons ) {
4543 // Map the key.
46- const newKey = await mapID ( key , state , key ) ;
44+ const newKey = await mapID ( lessonID , state ) ;
4745
4846 // Map next and previous.
49- const next = lessons [ key ] . next ?? [ ] ;
50- const previous = lessons [ key ] . previous ?? [ ] ;
47+ const next = lessons [ lessonID ] . next ?? [ ] ;
48+ const previous = lessons [ lessonID ] . previous ?? [ ] ;
5149
5250 if ( typeof next !== "object" || ! Array . isArray ( next ) )
5351 throw new Error ( "next must be a string array!" ) ;
@@ -58,17 +56,17 @@ export async function handleUnit(
5856 const newPrevious : string [ ] = [ ] ;
5957
6058 for ( const item of next ) {
61- newNext . push ( await mapID ( item , state , key ) ) ;
59+ newNext . push ( await mapID ( item , state ) ) ;
6260 }
6361
6462 for ( const item of previous ) {
65- newPrevious . push ( await mapID ( item , state , key ) ) ;
63+ newPrevious . push ( await mapID ( item , state ) ) ;
6664 }
6765
6866 map [ newKey ] = {
6967 next : newNext ,
7068 previous : newPrevious ,
71- requireAll : Boolean ( lessons [ key ] . requireAll ) ,
69+ requireAll : Boolean ( lessons [ lessonID ] . requireAll ) ,
7270 } ;
7371 }
7472
@@ -83,7 +81,7 @@ export async function handleUnit(
8381 } ,
8482 {
8583 headers : {
86- authorization : key ,
84+ authorization : state . key ,
8785 } ,
8886 } ,
8987 ) ;
@@ -92,17 +90,16 @@ export async function handleUnit(
9290
9391/**
9492 * Maps a friendly name or ID to an ID.
95- * @param id {string} - is
96- * @param state
97- * @param key
93+ * @param id {string} - is the ID or friendly name to lookup.
94+ * @param state {State} - is the application's state.
9895 */
99- async function mapID ( id : string , state : State , key : string ) : Promise < string > {
96+ async function mapID ( id : string , state : State ) : Promise < string > {
10097 const newKey =
10198 state . idsMap [ id ] ||
10299 ( await axios
103100 . get ( "https://cratecode.com/internal/api/id/" + id , {
104101 headers : {
105- authorization : key ,
102+ authorization : state . key ,
106103 } ,
107104 } )
108105 . then ( ( res ) => {
0 commit comments