-
-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcreate.examples.js
62 lines (56 loc) · 1.46 KB
/
create.examples.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict';
const { log, store } = require('./services');
// #create-record-example
const createRecord = client =>
client
.create('Heroes', {
name: 'George Lucas'
})
.then(result => log('create-record-example', result));
// #
//#create-record-merge
const mergeDataOnCreate = client =>
client
.create(
'Heroes',
{
name: 'George Lucas'
},
{ merge: true }
)
.then(result => log('create-record-merge-example', result));
// #
//#create-many-records
const createManyRecords = client =>
Promise.all([
client.create('Heroes', { name: 'Anakin Skywalker' }, { merge: true }),
client.create('Heroes', { name: 'Obi-Wan' }, { merge: true }),
client.create('Heroes', { name: 'Yoda' }, { merge: true })
]).then(result => log('create-many-records-example', result));
//#
//#trigger-scripts-on-create
const triggerScriptsOnCreate = client =>
client
.create(
'Heroes',
{ name: 'Anakin Skywalker' },
{
merge: true,
scripts: [
{ name: 'Create Droids', param: { droids: ['C3-PO', 'R2-D2'] } }
]
}
)
.then(result => log('trigger-scripts-on-create-example', result));
//#
const creates = (client, examples) =>
Promise.all([
createRecord(client),
mergeDataOnCreate(client),
createManyRecords(client),
triggerScriptsOnCreate(client)
]).then(responses => {
store(responses);
return client;
});
module.exports = { creates };