-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
profile-support.js
45 lines (39 loc) · 1.21 KB
/
profile-support.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
/* eslint-disable no-console */
const farmOS = require('../dist/cjs/farmOS').default;
const entities = require('../dist/cjs/entities');
const { default: defaultEntities, defaultOptions } = entities;
const profile = {
nomenclature: {
name: 'profile',
shortName: 'profile',
plural: 'profiles',
shortPlural: 'profiles',
display: 'Profile',
displayPlural: 'Profiles',
},
defaultOptions,
};
const host = 'http://localhost';
const clientId = 'fieldkit';
const username = 'farm';
const password = 'farm';
const farmOptions = {
remote: { host, clientId },
entities: { ...defaultEntities, profile },
};
const farm = farmOS(farmOptions);
farm.remote.authorize(username, password)
.then(() => farm.schema.fetch())
.then((res) => {
farm.schema.set(res);
const commonSchemata = farm.schema.get('profile', 'common');
console.log('common attributes:\n', Object.keys(commonSchemata.properties.attributes.properties));
const commonProfile = farm.profile.create({ type: 'profile--common', name: 'Maggie\'s Farm' });
console.log('commonProfile:\n', commonProfile);
})
.then(() => {
})
.catch((e) => {
const data = e && e.response && e.response.data;
console.error(data || e);
});