Client purge
This commit is contained in:
parent
45bc244e58
commit
f67f7a1627
|
|
@ -67,6 +67,14 @@ class ClientRepository {
|
||||||
return clientResponse.data.toList();
|
return clientResponse.data.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<bool> purge(Credentials credentials, String id) async {
|
||||||
|
final url = credentials.url + '/clients/$id/purge';
|
||||||
|
|
||||||
|
await webClient.post(url, credentials.token);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
Future<ClientEntity> saveData(
|
Future<ClientEntity> saveData(
|
||||||
Credentials credentials, ClientEntity client) async {
|
Credentials credentials, ClientEntity client) async {
|
||||||
client = client.rebuild((b) => b..documents.clear());
|
client = client.rebuild((b) => b..documents.clear());
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
// Flutter imports:
|
// Flutter imports:
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
// Package imports:
|
// Package imports:
|
||||||
|
|
@ -31,6 +33,7 @@ List<Middleware<AppState>> createStoreClientsMiddleware([
|
||||||
final saveClient = _saveClient(repository);
|
final saveClient = _saveClient(repository);
|
||||||
final archiveClient = _archiveClient(repository);
|
final archiveClient = _archiveClient(repository);
|
||||||
final deleteClient = _deleteClient(repository);
|
final deleteClient = _deleteClient(repository);
|
||||||
|
final purgeClient = _purgeClient(repository);
|
||||||
final restoreClient = _restoreClient(repository);
|
final restoreClient = _restoreClient(repository);
|
||||||
final saveDocument = _saveDocument(repository);
|
final saveDocument = _saveDocument(repository);
|
||||||
|
|
||||||
|
|
@ -44,6 +47,7 @@ List<Middleware<AppState>> createStoreClientsMiddleware([
|
||||||
TypedMiddleware<AppState, SaveClientRequest>(saveClient),
|
TypedMiddleware<AppState, SaveClientRequest>(saveClient),
|
||||||
TypedMiddleware<AppState, ArchiveClientsRequest>(archiveClient),
|
TypedMiddleware<AppState, ArchiveClientsRequest>(archiveClient),
|
||||||
TypedMiddleware<AppState, DeleteClientsRequest>(deleteClient),
|
TypedMiddleware<AppState, DeleteClientsRequest>(deleteClient),
|
||||||
|
TypedMiddleware<AppState, PurgeClientRequest>(purgeClient),
|
||||||
TypedMiddleware<AppState, RestoreClientsRequest>(restoreClient),
|
TypedMiddleware<AppState, RestoreClientsRequest>(restoreClient),
|
||||||
TypedMiddleware<AppState, SaveClientDocumentRequest>(saveDocument),
|
TypedMiddleware<AppState, SaveClientDocumentRequest>(saveDocument),
|
||||||
];
|
];
|
||||||
|
|
@ -147,6 +151,29 @@ Middleware<AppState> _deleteClient(ClientRepository repository) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Middleware<AppState> _purgeClient(ClientRepository repository) {
|
||||||
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
|
final action = dynamicAction as PurgeClientRequest;
|
||||||
|
repository.purge(store.state.credentials, action.clientId).then((_) {
|
||||||
|
store.dispatch(PurgeClientSuccess());
|
||||||
|
store.dispatch(RefreshData(
|
||||||
|
clearData: true,
|
||||||
|
completer: Completer<Null>()
|
||||||
|
..future.then((value) {
|
||||||
|
action.completer.complete(null);
|
||||||
|
})));
|
||||||
|
}).catchError((Object error) {
|
||||||
|
print(error);
|
||||||
|
store.dispatch(PurgeClientFailure(error));
|
||||||
|
if (action.completer != null) {
|
||||||
|
action.completer.completeError(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
next(action);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Middleware<AppState> _restoreClient(ClientRepository repository) {
|
Middleware<AppState> _restoreClient(ClientRepository repository) {
|
||||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
final action = dynamicAction as RestoreClientsRequest;
|
final action = dynamicAction as RestoreClientsRequest;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue