remove method

  1. @override
Future<Map<String, dynamic>> remove(
  1. String? id, [
  2. Map<String, dynamic>? params
])

Removes the given resource.

Implementation

@override
Future<Map<String, dynamic>> remove(String? id,
    [Map<String, dynamic>? params]) async {
  if (id == null || id == 'null') {
    // Remove everything...
    if (!(allowRemoveAll == true ||
        params?.containsKey('provider') != true)) {
      throw AngelHttpException.forbidden(
          message: 'Clients are not allowed to delete all items.');
    } else {
      await store.delete(database);
      return {};
    }
  }

  return database.transaction((txn) async {
    var record = store.record(int.parse(id));
    var snapshot = await record.getSnapshot(txn);

    if (snapshot == null) {
      throw AngelHttpException.notFound(
          message: 'No record found for ID $id');
    } else {
      await record.delete(txn);
    }

    return _withId(snapshot.value, id);
  });
}