[CHORE] Update to new server response (#1509)

This commit is contained in:
Djorkaeff Alexandre 2020-01-07 15:54:02 -03:00 committed by Diego Mello
parent 1aadb88392
commit 62db1ec950
1 changed files with 5 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import {
import { Alert } from 'react-native'; import { Alert } from 'react-native';
import RNUserDefaults from 'rn-user-defaults'; import RNUserDefaults from 'rn-user-defaults';
import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord'; import { sanitizedRaw } from '@nozbe/watermelondb/RawRecord';
import semver from 'semver';
import Navigation from '../lib/Navigation'; import Navigation from '../lib/Navigation';
import { SERVER } from '../actions/actionsTypes'; import { SERVER } from '../actions/actionsTypes';
@ -35,18 +36,20 @@ const getServerInfo = function* getServerInfo({ server, raiseError = true }) {
return; return;
} }
const validVersion = semver.coerce(serverInfo.version);
const serversDB = database.servers; const serversDB = database.servers;
const serversCollection = serversDB.collections.get('servers'); const serversCollection = serversDB.collections.get('servers');
yield serversDB.action(async() => { yield serversDB.action(async() => {
try { try {
const serverRecord = await serversCollection.find(server); const serverRecord = await serversCollection.find(server);
await serverRecord.update((record) => { await serverRecord.update((record) => {
record.version = serverInfo.version; record.version = validVersion;
}); });
} catch (e) { } catch (e) {
await serversCollection.create((record) => { await serversCollection.create((record) => {
record._raw = sanitizedRaw({ id: server }, serversCollection.schema); record._raw = sanitizedRaw({ id: server }, serversCollection.schema);
record.version = serverInfo.version; record.version = validVersion;
}); });
} }
}); });