deleteDoc method

  1. @override
Future<RequestResponse<String?>> deleteDoc(
  1. String? doctype,
  2. String? docName
)
override

Deletes the document from the backend, returning its name.

If the document exists in locals cache, it will be deleted as well.

Throws EmptyDoctypeError if doctype is null or an empty string.

Throws EmptyDocNameError if docName is null or an empty string.

Returns a failure if the document or doctype don't exist.

Implementation

@override
Future<RequestResponse<String?>> deleteDoc(
    String? doctype, String? docName) async {
  EmptyDoctypeError.verify(doctype);
  EmptyDocNameError.verify(docName);

  final response = await Request.initiateRequest(
      url:
          '${config.hostUrl}/api/resource/${Uri.encodeComponent(doctype!)}/${Uri.encodeComponent(docName!)}',
      method: HttpMethod.DELETE);
  if (response.isSuccess) {
    if (locals[doctype] != null && locals[doctype]![docName] != null) {
      locals[doctype]!.remove(docName);
    }
    return RequestResponse.success(docName);
  } else {
    return RequestResponse.fail(handleError('delete_doc', response.error));
  }
}