@@ -561,31 +561,30 @@ RestWrite.prototype.handleInstallation = function() {
561
561
return ;
562
562
}
563
563
564
- if ( ! this . query && ! this . data . deviceToken && ! this . data . installationId ) {
564
+ if ( ! this . query && ! this . data . deviceToken && ! this . data . installationId && ! this . auth . installationId ) {
565
565
throw new Parse . Error ( 135 ,
566
566
'at least one ID field (deviceToken, installationId) ' +
567
567
'must be specified in this operation' ) ;
568
568
}
569
569
570
- if ( ! this . query && ! this . data . deviceType ) {
571
- throw new Parse . Error ( 135 ,
572
- 'deviceType must be specified in this operation' ) ;
573
- }
574
-
575
570
// If the device token is 64 characters long, we assume it is for iOS
576
571
// and lowercase it.
577
572
if ( this . data . deviceToken && this . data . deviceToken . length == 64 ) {
578
573
this . data . deviceToken = this . data . deviceToken . toLowerCase ( ) ;
579
574
}
580
575
581
- // TODO: We may need installationId from headers, plumb through Auth?
582
- // per installation_handler.go
583
-
584
576
// We lowercase the installationId if present
585
577
if ( this . data . installationId ) {
586
578
this . data . installationId = this . data . installationId . toLowerCase ( ) ;
587
579
}
588
580
581
+ // If data.installationId is not set, we can lookup in the auth
582
+ let installationId = this . data . installationId || this . auth . installationId ;
583
+
584
+ if ( installationId ) {
585
+ installationId = installationId . toLowerCase ( ) ;
586
+ }
587
+
589
588
var promise = Promise . resolve ( ) ;
590
589
591
590
var idMatch ; // Will be a match on either objectId or installationId
@@ -600,9 +599,9 @@ RestWrite.prototype.handleInstallation = function() {
600
599
objectId : this . query . objectId
601
600
} ) ;
602
601
}
603
- if ( this . data . installationId ) {
602
+ if ( installationId ) {
604
603
orQueries . push ( {
605
- 'installationId' : this . data . installationId
604
+ 'installationId' : installationId
606
605
} ) ;
607
606
}
608
607
if ( this . data . deviceToken ) {
@@ -622,7 +621,7 @@ RestWrite.prototype.handleInstallation = function() {
622
621
if ( this . query && this . query . objectId && result . objectId == this . query . objectId ) {
623
622
objectIdMatch = result ;
624
623
}
625
- if ( result . installationId == this . data . installationId ) {
624
+ if ( result . installationId == installationId ) {
626
625
installationIdMatch = result ;
627
626
}
628
627
if ( result . deviceToken == this . data . deviceToken ) {
@@ -636,8 +635,8 @@ RestWrite.prototype.handleInstallation = function() {
636
635
throw new Parse . Error ( Parse . Error . OBJECT_NOT_FOUND ,
637
636
'Object not found for update.' ) ;
638
637
}
639
- if ( this . data . installationId && objectIdMatch . installationId &&
640
- this . data . installationId !== objectIdMatch . installationId ) {
638
+ if ( installationId && objectIdMatch . installationId &&
639
+ installationId !== objectIdMatch . installationId ) {
641
640
throw new Parse . Error ( 136 ,
642
641
'installationId may not be changed in this ' +
643
642
'operation' ) ;
@@ -661,16 +660,21 @@ RestWrite.prototype.handleInstallation = function() {
661
660
idMatch = objectIdMatch ;
662
661
}
663
662
664
- if ( this . data . installationId && installationIdMatch ) {
663
+ if ( installationId && installationIdMatch ) {
665
664
idMatch = installationIdMatch ;
666
665
}
666
+ // need to specify deviceType only if it's new
667
+ if ( ! this . query && ! this . data . deviceType && ! idMatch ) {
668
+ throw new Parse . Error ( 135 ,
669
+ 'deviceType must be specified in this operation' ) ;
670
+ }
667
671
668
672
} ) . then ( ( ) => {
669
673
if ( ! idMatch ) {
670
674
if ( ! deviceTokenMatches . length ) {
671
675
return ;
672
676
} else if ( deviceTokenMatches . length == 1 &&
673
- ( ! deviceTokenMatches [ 0 ] [ 'installationId' ] || ! this . data . installationId )
677
+ ( ! deviceTokenMatches [ 0 ] [ 'installationId' ] || ! installationId )
674
678
) {
675
679
// Single match on device token but none on installationId, and either
676
680
// the passed object or the match is missing an installationId, so we
@@ -689,7 +693,7 @@ RestWrite.prototype.handleInstallation = function() {
689
693
var delQuery = {
690
694
'deviceToken' : this . data . deviceToken ,
691
695
'installationId' : {
692
- '$ne' : this . data . installationId
696
+ '$ne' : installationId
693
697
}
694
698
} ;
695
699
if ( this . data . appIdentifier ) {
0 commit comments