11import { Logger } from "@nestjs/common"
22import { InjectConnection , InjectModel } from "@nestjs/mongoose"
33import { Connection , Model } from "mongoose"
4+ import { isNumber } from "radash"
45
56export default class LifeCycle1752765731 {
67 private readonly logger = new Logger ( LifeCycle1752765731 . name )
78
8- public constructor (
9- @InjectConnection ( ) private mongo : Connection ,
10- ) {
9+ public constructor ( @InjectConnection ( ) private mongo : Connection ) {
1110 }
1211
1312 public async up ( ) : Promise < void > {
@@ -20,11 +19,15 @@ export default class LifeCycle1752765731 {
2019 const identities = await this . mongo . collection ( 'identities' ) . find ( ) ;
2120
2221 for await ( const identity of identities ) {
23- const lifecycle = identity . lifecycle ;
22+ let lifecycle = identity . lifecycle ;
2423
25- if ( typeof lifecycle === 'number' ) {
24+ if ( typeof lifecycle === 'number' || isNumber ( lifecycle ) ) {
2625 this . logger . log ( `Migrating lifecycle for identity ${ identity . _id } ` ) ;
2726
27+ if ( typeof lifecycle === 'string' ) {
28+ lifecycle = parseInt ( lifecycle , 10 ) ;
29+ }
30+
2831 switch ( lifecycle ) {
2932 case 0 :
3033 identity . lifecycle = 'P' ; // PROVISIONAL
@@ -54,7 +57,7 @@ export default class LifeCycle1752765731 {
5457 { _id : identity . _id } ,
5558 {
5659 $set : {
57- 'inetOrgPerson. lifecycle' : identity . lifecycle ,
60+ lifecycle : identity . lifecycle ,
5861 ignoreLifecycle : false ,
5962 }
6063 } ,
0 commit comments