@@ -1410,6 +1410,136 @@ Kuzzle.prototype.getServerInfo = function (options, cb) {
1410
1410
return this ;
1411
1411
} ;
1412
1412
1413
+ /**
1414
+ * Forces an index refresh
1415
+ *
1416
+ * @param {string } index - The index to refresh. Defaults to Kuzzle.defaultIndex
1417
+ * @param {object } options - Optional arguments
1418
+ * @param {responseCallback } cb - Handles the query response
1419
+ * @returns {Kuzzle }
1420
+ */
1421
+ Kuzzle . prototype . refreshIndex = function ( ) {
1422
+ var
1423
+ index ,
1424
+ options ,
1425
+ cb ;
1426
+
1427
+ Array . prototype . slice . call ( arguments ) . forEach ( function ( arg ) {
1428
+ switch ( typeof arg ) {
1429
+ case 'string' :
1430
+ index = arg ;
1431
+ break ;
1432
+ case 'object' :
1433
+ options = arg ;
1434
+ break ;
1435
+ case 'function' :
1436
+ cb = arg ;
1437
+ break ;
1438
+ }
1439
+ } ) ;
1440
+
1441
+ if ( ! index ) {
1442
+ if ( ! this . defaultIndex ) {
1443
+ throw new Error ( 'Kuzzle.refreshIndex: index required' ) ;
1444
+ }
1445
+ index = this . defaultIndex ;
1446
+ }
1447
+
1448
+ this . query ( { index : index , controller : 'admin' , action : 'refreshIndex' } , { } , options , cb ) ;
1449
+
1450
+ return this ;
1451
+ } ;
1452
+
1453
+ /**
1454
+ * Returns de current autoRefresh status for the given index
1455
+ *
1456
+ * @param {string } index - The index to get the status from. Defaults to Kuzzle.defaultIndex
1457
+ * @param {object } options - Optinal arguments
1458
+ * @param {responseCallback } cb - Handles the query response
1459
+ * @returns {object } this
1460
+ */
1461
+ Kuzzle . prototype . getAutoRefresh = function ( ) {
1462
+ var
1463
+ index ,
1464
+ options ,
1465
+ cb ;
1466
+
1467
+ Array . prototype . slice . call ( arguments ) . forEach ( function ( arg ) {
1468
+ switch ( typeof arg ) {
1469
+ case 'string' :
1470
+ index = arg ;
1471
+ break ;
1472
+ case 'object' :
1473
+ options = arg ;
1474
+ break ;
1475
+ case 'function' :
1476
+ cb = arg ;
1477
+ break ;
1478
+ }
1479
+ } ) ;
1480
+
1481
+ if ( ! index ) {
1482
+ if ( ! this . defaultIndex ) {
1483
+ throw new Error ( 'Kuzzle.getAutoRefresh: index required' ) ;
1484
+ }
1485
+ index = this . defaultIndex ;
1486
+ }
1487
+
1488
+ this . callbackRequired ( 'Kuzzle.getAutoRefresh' , cb ) ;
1489
+ this . query ( { index : index , controller : 'admin' , action : 'getAutoRefresh' } , { } , options , cb ) ;
1490
+
1491
+ return this ;
1492
+ } ;
1493
+
1494
+ /**
1495
+ * (Un)Sets the autoRefresh flag on the given index
1496
+ *
1497
+ * @param {string } index - the index to modify. Defaults to Kuzzle.defaultIndex
1498
+ * @param {boolean } autoRefresh - The autoRefresh value to set
1499
+ * @param {object } options - Optional arguments
1500
+ * @param {responseCallback } cb - Handles the query result
1501
+ * @returns {object } this
1502
+ */
1503
+ Kuzzle . prototype . setAutoRefresh = function ( ) {
1504
+ var
1505
+ index ,
1506
+ autoRefresh ,
1507
+ options ,
1508
+ cb ;
1509
+
1510
+ Array . prototype . slice . call ( arguments ) . forEach ( function ( arg ) {
1511
+ switch ( typeof arg ) {
1512
+ case 'string' :
1513
+ index = arg ;
1514
+ break ;
1515
+ case 'boolean' :
1516
+ autoRefresh = arg ;
1517
+ break ;
1518
+ case 'object' :
1519
+ options = arg ;
1520
+ break ;
1521
+ case 'function' :
1522
+ cb = arg ;
1523
+ break ;
1524
+ }
1525
+ } ) ;
1526
+
1527
+ if ( ! index ) {
1528
+ if ( ! this . defaultIndex ) {
1529
+ throw new Error ( 'Kuzzle.setAutoRefresh: index required' ) ;
1530
+ }
1531
+ index = this . defaultIndex ;
1532
+ }
1533
+
1534
+ if ( autoRefresh === undefined ) {
1535
+ throw new Error ( 'Kuzzle.setAutoRefresh: autoRefresh value is required' ) ;
1536
+ }
1537
+
1538
+ this . query ( { index : index , controller : 'admin' , action : 'setAutoRefresh' } , { body : { autoRefresh : autoRefresh } } , options , cb ) ;
1539
+
1540
+ return this ;
1541
+ } ;
1542
+
1413
1543
/**
1414
1544
* Return the current Kuzzle's UTC Epoch time, in milliseconds
1415
1545
* @param {object } [options] - Optional parameters
@@ -1958,8 +2088,6 @@ KuzzleDataCollection.prototype.deleteDocument = function (arg, options, cb) {
1958
2088
} else {
1959
2089
this . kuzzle . query ( this . buildQueryArgs ( 'write' , action ) , data , options ) ;
1960
2090
}
1961
-
1962
- return this ;
1963
2091
} ;
1964
2092
1965
2093
/**
@@ -2564,7 +2692,7 @@ KuzzleDocument.prototype.delete = function (options, cb) {
2564
2692
options = null ;
2565
2693
}
2566
2694
2567
- if ( ! this . id ) {
2695
+ if ( ! self . id ) {
2568
2696
throw new Error ( 'KuzzleDocument.delete: cannot delete a document without a document ID' ) ;
2569
2697
}
2570
2698
@@ -2574,13 +2702,11 @@ KuzzleDocument.prototype.delete = function (options, cb) {
2574
2702
return cb ( err ) ;
2575
2703
}
2576
2704
2577
- cb ( null , self ) ;
2705
+ cb ( null , self . id ) ;
2578
2706
} ) ;
2579
2707
} else {
2580
2708
this . kuzzle . query ( this . dataCollection . buildQueryArgs ( 'write' , 'delete' ) , this . serialize ( ) , options ) ;
2581
2709
}
2582
-
2583
- return this ;
2584
2710
} ;
2585
2711
2586
2712
/**
@@ -3805,12 +3931,12 @@ KuzzleSecurity.prototype.updateRole = function (id, content, options, cb) {
3805
3931
data . body = content ;
3806
3932
3807
3933
if ( cb ) {
3808
- self . kuzzle . query ( this . buildQueryArgs ( action ) , data , options , function ( err , res ) {
3934
+ self . kuzzle . query ( this . buildQueryArgs ( action ) , data , options , function ( err ) {
3809
3935
if ( err ) {
3810
3936
return cb ( err ) ;
3811
3937
}
3812
3938
3813
- cb ( null , res . result . _id ) ;
3939
+ cb ( null , new KuzzleRole ( self , id , content ) ) ;
3814
3940
} ) ;
3815
3941
} else {
3816
3942
self . kuzzle . query ( this . buildQueryArgs ( action ) , data ) ;
@@ -4038,11 +4164,23 @@ KuzzleSecurity.prototype.updateProfile = function (id, content, options, cb) {
4038
4164
4039
4165
if ( cb ) {
4040
4166
self . kuzzle . query ( this . buildQueryArgs ( action ) , data , options , function ( err , res ) {
4167
+ var updatedContent = { } ;
4168
+
4041
4169
if ( err ) {
4042
4170
return cb ( err ) ;
4043
4171
}
4044
4172
4045
- cb ( null , res . result . _id ) ;
4173
+ Object . keys ( res . result . _source ) . forEach ( function ( property ) {
4174
+ if ( property !== 'roles' ) {
4175
+ updatedContent [ property ] = res . result . _source [ property ] ;
4176
+ }
4177
+ } ) ;
4178
+
4179
+ updatedContent . roles = res . result . _source . roles . map ( function ( role ) {
4180
+ return role . _id ;
4181
+ } ) ;
4182
+
4183
+ cb ( null , new KuzzleProfile ( self , res . result . _id , updatedContent ) ) ;
4046
4184
} ) ;
4047
4185
} else {
4048
4186
self . kuzzle . query ( this . buildQueryArgs ( action ) , data ) ;
0 commit comments