@@ -16,6 +16,13 @@ const FEATURE_NAME = 'compliance_hub';
1616
1717 plugins . internalDrillEvents . push ( "[CLY]_consent" ) ;
1818
19+ plugins . register ( "/master" , function ( ) {
20+ common . db . collection ( 'consent_history' ) . ensureIndex ( { app_id : 1 , device_id : 1 } , function ( ) { } ) ;
21+ common . db . collection ( 'consent_history' ) . ensureIndex ( { app_id : 1 , uid : 1 } , function ( ) { } ) ;
22+ common . db . collection ( 'consent_history' ) . ensureIndex ( { app_id : 1 , type : 1 } , function ( ) { } ) ;
23+ common . db . collection ( 'consent_history' ) . ensureIndex ( { app_id : 1 , ts : 1 } , function ( ) { } ) ;
24+ } ) ;
25+
1926 //write api call
2027 plugins . register ( "/sdk/user_properties" , function ( ob ) {
2128 var params = ob . params ;
@@ -142,7 +149,7 @@ const FEATURE_NAME = 'compliance_hub';
142149 }
143150 }
144151 common . db . collection ( "app_users" + params . qstring . app_id ) . findOne ( query , function ( err , res ) {
145- common . returnOutput ( params , res . consent || { } ) ;
152+ common . returnOutput ( params , res ? .consent || { } ) ;
146153 } ) ;
147154 } ) ;
148155 break ;
@@ -162,7 +169,8 @@ const FEATURE_NAME = 'compliance_hub';
162169 query = { } ;
163170 }
164171 }
165- common . db . collection ( "consent_history" ) . count ( query , function ( err , total ) {
172+ query . app_id = params . app_id . toString ( ) ;
173+ common . db . collection ( "consent_history" ) . countDocuments ( query , function ( err , total ) {
166174 if ( err ) {
167175 common . returnMessage ( params , 400 , err ) ;
168176 }
@@ -338,7 +346,7 @@ const FEATURE_NAME = 'compliance_hub';
338346 var newUid = ob . newUser . uid ;
339347 if ( oldUid !== newUid ) {
340348 return new Promise ( function ( resolve , reject ) {
341- common . db . collection ( 'consent_history' ) . update ( { uid : oldUid } , { '$set' : { uid : newUid } } , { multi : true } , function ( err ) {
349+ common . db . collection ( 'consent_history' ) . update ( { uid : oldUid } , { '$set' : { app_id : ob . app_id , uid : newUid } } , { multi : true } , function ( err ) {
342350 if ( err ) {
343351 reject ( err ) ;
344352 return ;
@@ -364,7 +372,7 @@ const FEATURE_NAME = 'compliance_hub';
364372 plugins . register ( "/i/apps/delete" , function ( ob ) {
365373 var appId = ob . appId ;
366374 common . db . collection ( 'consents' ) . remove ( { '_id' : { $regex : appId + ".*" } } , function ( ) { } ) ;
367- common . db . collection ( 'consent_history' ) . drop ( function ( ) { } ) ;
375+ common . db . collection ( 'consent_history' ) . deleteMany ( { app_id : appId } , function ( ) { } ) ;
368376 if ( common . drillDb ) {
369377 common . drillDb . collection ( "drill_events" + crypto . createHash ( 'sha1' ) . update ( "[CLY]_consent" + appId ) . digest ( 'hex' ) ) . drop ( function ( ) { } ) ;
370378 }
@@ -373,7 +381,7 @@ const FEATURE_NAME = 'compliance_hub';
373381 plugins . register ( "/i/apps/reset" , function ( ob ) {
374382 var appId = ob . appId ;
375383 common . db . collection ( 'consents' ) . remove ( { '_id' : { $regex : appId + ".*" } } , function ( ) { } ) ;
376- common . db . collection ( 'consent_history' ) . drop ( function ( ) { } ) ;
384+ common . db . collection ( 'consent_history' ) . deleteMany ( { app_id : appId } , function ( ) { } ) ;
377385 if ( common . drillDb ) {
378386 common . drillDb . collection ( "drill_events" + crypto . createHash ( 'sha1' ) . update ( "[CLY]_consent" + appId ) . digest ( 'hex' ) ) . drop ( function ( ) { } ) ;
379387 }
@@ -382,6 +390,7 @@ const FEATURE_NAME = 'compliance_hub';
382390 plugins . register ( "/i/apps/clear_all" , function ( ob ) {
383391 var appId = ob . appId ;
384392 common . db . collection ( 'consents' ) . remove ( { '_id' : { $regex : appId + ".*" } } , function ( ) { } ) ;
393+ common . db . collection ( 'consent_history' ) . deleteMany ( { app_id : appId } , function ( ) { } ) ;
385394 if ( common . drillDb ) {
386395 common . drillDb . collection ( "drill_events" + crypto . createHash ( 'sha1' ) . update ( "[CLY]_consent" + appId ) . digest ( 'hex' ) ) . drop ( function ( ) { } ) ;
387396 }
@@ -391,6 +400,7 @@ const FEATURE_NAME = 'compliance_hub';
391400 var appId = ob . appId ;
392401 var ids = ob . ids ;
393402 common . db . collection ( 'consents' ) . remove ( { $and : [ { '_id' : { $regex : appId + ".*" } } , { '_id' : { $nin : ids } } ] } , function ( ) { } ) ;
403+ common . db . collection ( 'consent_history' ) . deleteMany ( { app_id : appId , ts : { $lt : ob . moment . valueOf ( ) } } , function ( ) { } ) ;
394404 if ( common . drillDb ) {
395405 common . drillDb . collection ( "drill_events" + crypto . createHash ( 'sha1' ) . update ( "[CLY]_consent" + appId ) . digest ( 'hex' ) ) . remove ( { ts : { $lt : ob . moment . valueOf ( ) } } , function ( ) { } ) ;
396406 }
0 commit comments