-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathadd_user.js
40 lines (37 loc) · 929 Bytes
/
add_user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
var Kuzzle = require('kuzzle-sdk')
var config = require('./config/default.json')
var Enquirer = require('enquirer')
var k_cfg = config.kuzzle
var enquirer = new Enquirer()
var user_questions = [
{
name: 'forname',
message: 'Forname: ',
default: 'John'
},
{
name: 'surname',
message: 'Surname: ',
default: 'Doe'
},
{
name: 'email',
message: 'email: ',
default: '[email protected]'
}
]
var kuzzle = new Kuzzle(k_cfg.host, {defaultIndex: k_cfg.index},
() => {
kuzzle.loginPromise('local', k_cfg.user, '1d')
.then( () => enquirer.ask(user_questions))
.then(user_data => {
kuzzle.collection('users').createDocumentPromise(
{
forname: user_data.forname,
surname: user_data.surname,
email: user_data.email
})
})
.catch(err => console.log(err))
.then(() => kuzzle.disconnect())
})