delete method

  1. @override
Future<Map<String, dynamic>> delete(
  1. String key,
  2. DbPrincipal principal, {
  3. DeletePolicy? deletePolicy,
  4. RepositoryTransaction? transaction,
})

Deletes the entity from the collection identified by the key parameter.

This method expects a principal parameter, which identifies the user performing the request. Implementations are advised to confirm if the entity being deleted belongs to a tenant related to the principal.

If a non-empty value is passed to the permission parameter, the implementation of this method is expected to validate if the user represented by the principal does have the permission before actually inserting the entity. Otherwise, an error is thrown.

Implementation

@override
Future<Map<String, dynamic>> delete(
  String key,
  DbPrincipal principal, {
  DeletePolicy? deletePolicy,
  RepositoryTransaction? transaction,
}) async {
  var map = await _get(key, principal);

  deletePolicy ??= this.deletePolicy;
  handleMetaForDelete(map, principal, deletePolicy);
  _authorize(map, principal, deletePolicy);
  final trx = _getDriverTransaction(transaction);

  try {
    await db.removeDocument(
      collectionName,
      key,
      transaction: trx,
    );
  } on DbError catch (error) {
    throw error.toDbException();
  }
  return map;
}