Commit 951a95c 1 parent 4de15fb commit 951a95c Copy full SHA for 951a95c
File tree 1 file changed +8
-3
lines changed
1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 1
1
/* eslint-disable no-console */
2
2
3
- import { usernameCollection , semestersCollection } from '../firebase-config' ;
3
+ import { semestersCollection } from '../firebase-config' ;
4
4
5
5
/**
6
6
* Perform migration of semester to plans with a list of semesters
7
7
*/
8
8
async function runOnUser ( userEmail : string ) {
9
9
const semestersDoc = await semestersCollection . doc ( userEmail ) . get ( ) ;
10
10
const semesters = semestersDoc . data ( ) ?. semesters ?? [ ] ;
11
+ const currplans = semestersDoc . data ( ) ?. plans ?? [ ] ;
12
+ const newplans =
13
+ currplans . length >= 1
14
+ ? currplans . map ( p => ( ! ( 'name' in p ) ? { name : 'Plan 1' , semesters } : p ) )
15
+ : [ { name : 'Plan 1' , semesters } ] ;
11
16
await semestersCollection . doc ( userEmail ) . update ( {
12
- plans : [ { name : 'Plan 1' , semesters } ] ,
17
+ plans : newplans ,
13
18
} ) ;
14
19
}
15
20
@@ -19,7 +24,7 @@ async function main() {
19
24
await runOnUser ( userEmail ) ;
20
25
return ;
21
26
}
22
- const collection = await usernameCollection . get ( ) ;
27
+ const collection = await semestersCollection . get ( ) ;
23
28
for ( const { id } of collection . docs ) {
24
29
console . group ( `Running on ${ id } ...` ) ;
25
30
// Intentionally await in a loop to have no interleaved console logs.
You can’t perform that action at this time.
0 commit comments