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') {
    // Remove everything...
    if (!(allowRemoveAll == true ||
        params?.containsKey('provider') != true)) {
      throw AngelHttpException.forbidden(
          message: 'Clients are not allowed to delete all items.');
    } else {
      await collection.remove(null);
      return {};
    }
  }

  // var result = await read(id, params);

  try {
    var result = await (collection.findAndModify(
        query: where.id(_makeId(id)),
        remove: true) as FutureOr<Map<String, dynamic>>);
    return _jsonify(result);
  } catch (e, st) {
    //printDebug(e, st, 'REMOVE');
    throw AngelHttpException(stackTrace: st);
  }
}