@@ -163,6 +163,46 @@ KuzzleSecurity.prototype.createRole = function (id, content, options, cb) {
163
163
}
164
164
} ;
165
165
166
+
167
+ /**
168
+ * Update a role in Kuzzle.
169
+ *
170
+ * @param {string } id - role identifier
171
+ * @param {object } content - a plain javascript object representing the role's modification
172
+ * @param {object } [options] - (optional) arguments
173
+ * @param {responseCallback } [cb] - (optional) Handles the query response
174
+ */
175
+ KuzzleSecurity . prototype . updateRole = function ( id , content , options , cb ) {
176
+ var
177
+ self = this ,
178
+ data = { } ,
179
+ action = 'updateRole' ;
180
+
181
+ if ( ! id || typeof id !== 'string' ) {
182
+ throw new Error ( 'KuzzleSecurity.updateRole: cannot update a role without a role ID' ) ;
183
+ }
184
+
185
+ if ( ! cb && typeof options === 'function' ) {
186
+ cb = options ;
187
+ options = null ;
188
+ }
189
+
190
+ data . _id = id ;
191
+ data . body = content ;
192
+
193
+ if ( cb ) {
194
+ self . kuzzle . query ( this . buildQueryArgs ( action ) , data , options , function ( err , res ) {
195
+ if ( err ) {
196
+ return cb ( err ) ;
197
+ }
198
+
199
+ cb ( null , res . result . _id ) ;
200
+ } ) ;
201
+ } else {
202
+ self . kuzzle . query ( this . buildQueryArgs ( action ) , data ) ;
203
+ }
204
+ } ;
205
+
166
206
/**
167
207
* Delete role.
168
208
*
@@ -355,6 +395,46 @@ KuzzleSecurity.prototype.createProfile = function (id, content, options, cb) {
355
395
}
356
396
} ;
357
397
398
+
399
+ /**
400
+ * Update a profile in Kuzzle.
401
+ *
402
+ * @param {string } id - profile identifier
403
+ * @param {object } content - a plain javascript object representing the profile's modification
404
+ * @param {object } [options] - (optional) arguments
405
+ * @param {responseCallback } [cb] - (optional) Handles the query response
406
+ */
407
+ KuzzleSecurity . prototype . updateProfile = function ( id , content , options , cb ) {
408
+ var
409
+ self = this ,
410
+ data = { } ,
411
+ action = 'updateProfile' ;
412
+
413
+ if ( ! id || typeof id !== 'string' ) {
414
+ throw new Error ( 'KuzzleSecurity.updateProfile: cannot update a profile without a profile ID' ) ;
415
+ }
416
+
417
+ if ( ! cb && typeof options === 'function' ) {
418
+ cb = options ;
419
+ options = null ;
420
+ }
421
+
422
+ data . _id = id ;
423
+ data . body = content ;
424
+
425
+ if ( cb ) {
426
+ self . kuzzle . query ( this . buildQueryArgs ( action ) , data , options , function ( err , res ) {
427
+ if ( err ) {
428
+ return cb ( err ) ;
429
+ }
430
+
431
+ cb ( null , res . result . _id ) ;
432
+ } ) ;
433
+ } else {
434
+ self . kuzzle . query ( this . buildQueryArgs ( action ) , data ) ;
435
+ }
436
+ } ;
437
+
358
438
/**
359
439
* Delete profile.
360
440
*
@@ -544,6 +624,46 @@ KuzzleSecurity.prototype.createUser = function (id, content, options, cb) {
544
624
}
545
625
} ;
546
626
627
+
628
+ /**
629
+ * Update an user in Kuzzle.
630
+ *
631
+ * @param {string } id - user identifier
632
+ * @param {object } content - a plain javascript object representing the user's modification
633
+ * @param {object } [options] - (optional) arguments
634
+ * @param {responseCallback } [cb] - (optional) Handles the query response
635
+ */
636
+ KuzzleSecurity . prototype . updateUser = function ( id , content , options , cb ) {
637
+ var
638
+ self = this ,
639
+ data = { } ,
640
+ action = 'updateUser' ;
641
+
642
+ if ( ! id || typeof id !== 'string' ) {
643
+ throw new Error ( 'KuzzleSecurity.updateUser: cannot update an user without an user ID' ) ;
644
+ }
645
+
646
+ if ( ! cb && typeof options === 'function' ) {
647
+ cb = options ;
648
+ options = null ;
649
+ }
650
+
651
+ data . _id = id ;
652
+ data . body = content ;
653
+
654
+ if ( cb ) {
655
+ self . kuzzle . query ( this . buildQueryArgs ( action ) , data , options , function ( err , res ) {
656
+ if ( err ) {
657
+ return cb ( err ) ;
658
+ }
659
+
660
+ cb ( null , res . result . _id ) ;
661
+ } ) ;
662
+ } else {
663
+ self . kuzzle . query ( this . buildQueryArgs ( action ) , data ) ;
664
+ }
665
+ } ;
666
+
547
667
/**
548
668
* Delete user.
549
669
*
0 commit comments