[FIX] getSettings not catching errors (#2271)
This commit is contained in:
parent
aef7125887
commit
f3b02a6a88
|
@ -1,4 +1,3 @@
|
||||||
import { InteractionManager } from 'react-native';
|
|
||||||
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
|
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
|
||||||
import { Q } from '@nozbe/watermelondb';
|
import { Q } from '@nozbe/watermelondb';
|
||||||
|
|
||||||
|
@ -132,48 +131,47 @@ export default async function() {
|
||||||
const filteredSettingsIds = filteredSettings.map(s => s._id);
|
const filteredSettingsIds = filteredSettings.map(s => s._id);
|
||||||
|
|
||||||
reduxStore.dispatch(addSettings(this.parseSettings(filteredSettings)));
|
reduxStore.dispatch(addSettings(this.parseSettings(filteredSettings)));
|
||||||
InteractionManager.runAfterInteractions(async() => {
|
|
||||||
// filter server info
|
|
||||||
const serverInfo = filteredSettings.filter(i1 => serverInfoKeys.includes(i1._id));
|
|
||||||
const iconSetting = data.find(item => item._id === 'Assets_favicon_512');
|
|
||||||
await serverInfoUpdate(serverInfo, iconSetting);
|
|
||||||
|
|
||||||
await db.action(async() => {
|
// filter server info
|
||||||
const settingsCollection = db.collections.get('settings');
|
const serverInfo = filteredSettings.filter(i1 => serverInfoKeys.includes(i1._id));
|
||||||
const allSettingsRecords = await settingsCollection
|
const iconSetting = data.find(item => item._id === 'Assets_favicon_512');
|
||||||
.query(Q.where('id', Q.oneOf(filteredSettingsIds)))
|
await serverInfoUpdate(serverInfo, iconSetting);
|
||||||
.fetch();
|
|
||||||
|
|
||||||
// filter settings
|
await db.action(async() => {
|
||||||
let settingsToCreate = filteredSettings.filter(i1 => !allSettingsRecords.find(i2 => i1._id === i2.id));
|
const settingsCollection = db.collections.get('settings');
|
||||||
let settingsToUpdate = allSettingsRecords.filter(i1 => filteredSettings.find(i2 => i1.id === i2._id));
|
const allSettingsRecords = await settingsCollection
|
||||||
|
.query(Q.where('id', Q.oneOf(filteredSettingsIds)))
|
||||||
|
.fetch();
|
||||||
|
|
||||||
// Create
|
// filter settings
|
||||||
settingsToCreate = settingsToCreate.map(setting => settingsCollection.prepareCreate(protectedFunction((s) => {
|
let settingsToCreate = filteredSettings.filter(i1 => !allSettingsRecords.find(i2 => i1._id === i2.id));
|
||||||
s._raw = sanitizedRaw({ id: setting._id }, settingsCollection.schema);
|
let settingsToUpdate = allSettingsRecords.filter(i1 => filteredSettings.find(i2 => i1.id === i2._id));
|
||||||
Object.assign(s, setting);
|
|
||||||
})));
|
|
||||||
|
|
||||||
// Update
|
// Create
|
||||||
settingsToUpdate = settingsToUpdate.map((setting) => {
|
settingsToCreate = settingsToCreate.map(setting => settingsCollection.prepareCreate(protectedFunction((s) => {
|
||||||
const newSetting = filteredSettings.find(s => s._id === setting.id);
|
s._raw = sanitizedRaw({ id: setting._id }, settingsCollection.schema);
|
||||||
return setting.prepareUpdate(protectedFunction((s) => {
|
Object.assign(s, setting);
|
||||||
Object.assign(s, newSetting);
|
})));
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
const allRecords = [
|
// Update
|
||||||
...settingsToCreate,
|
settingsToUpdate = settingsToUpdate.map((setting) => {
|
||||||
...settingsToUpdate
|
const newSetting = filteredSettings.find(s => s._id === setting.id);
|
||||||
];
|
return setting.prepareUpdate(protectedFunction((s) => {
|
||||||
|
Object.assign(s, newSetting);
|
||||||
try {
|
}));
|
||||||
await db.batch(...allRecords);
|
|
||||||
} catch (e) {
|
|
||||||
log(e);
|
|
||||||
}
|
|
||||||
return allRecords.length;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const allRecords = [
|
||||||
|
...settingsToCreate,
|
||||||
|
...settingsToUpdate
|
||||||
|
];
|
||||||
|
|
||||||
|
try {
|
||||||
|
await db.batch(...allRecords);
|
||||||
|
} catch (e) {
|
||||||
|
log(e);
|
||||||
|
}
|
||||||
|
return allRecords.length;
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
log(e);
|
log(e);
|
||||||
|
|
Loading…
Reference in New Issue