2019-04-26 21:15:25 +00:00
|
|
|
import { InteractionManager } from 'react-native';
|
|
|
|
|
|
|
|
import database from '../realm';
|
|
|
|
import log from '../../utils/log';
|
|
|
|
|
2019-06-17 13:57:07 +00:00
|
|
|
export default function() {
|
|
|
|
return new Promise(async(resolve) => {
|
|
|
|
try {
|
|
|
|
// RC 0.70.0
|
|
|
|
const result = await this.sdk.get('roles.list');
|
2019-04-26 21:15:25 +00:00
|
|
|
|
2019-06-17 13:57:07 +00:00
|
|
|
if (!result.success) {
|
|
|
|
return resolve();
|
|
|
|
}
|
2019-04-26 21:15:25 +00:00
|
|
|
|
2019-06-17 13:57:07 +00:00
|
|
|
const { roles } = result;
|
2019-04-26 21:15:25 +00:00
|
|
|
|
2019-06-17 13:57:07 +00:00
|
|
|
if (roles && roles.length) {
|
|
|
|
InteractionManager.runAfterInteractions(() => {
|
|
|
|
database.write(() => roles.forEach((role) => {
|
|
|
|
try {
|
|
|
|
database.create('roles', role, true);
|
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2019-06-17 13:57:07 +00:00
|
|
|
}
|
|
|
|
}));
|
|
|
|
return resolve();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
} catch (e) {
|
2019-08-23 13:18:47 +00:00
|
|
|
log(e);
|
2019-06-17 13:57:07 +00:00
|
|
|
return resolve();
|
2019-04-26 21:15:25 +00:00
|
|
|
}
|
2019-06-17 13:57:07 +00:00
|
|
|
});
|
2019-04-26 21:15:25 +00:00
|
|
|
}
|