addTag method

  1. @override
Future<RequestResponse<String?>> addTag({
  1. required String doctype,
  2. required String docName,
  3. required String tag,
})
override

Adds a tag to document docName of a doctype.

If the document is tagged with the same tag, it will silently return success.

Returns failure if the doctype or docname are invalid.

Implementation

@override
Future<RequestResponse<String?>> addTag(
    {required String doctype,
    required String docName,
    required String tag}) async {
  EmptyDoctypeError.verify(doctype);
  EmptyDocNameError.verify(docName);
  final args = {
    'cmd': config.coreInstance.frappe.frappeVersion!.major == 12
        ? 'frappe.desk.doctype.tag.tag.add_tag'
        : 'frappe.desk.tags.add_tag',
    'dt': doctype,
    'dn': docName,
    'tag': tag
  };

  final response = await Request.initiateRequest(
      url: config.hostUrl,
      method: HttpMethod.POST,
      contentType: ContentTypeLiterals.APPLICATION_JSON,
      data: args);

  if (response.isSuccess) {
    return RequestResponse.success(response.data!.message,
        rawResponse: response.rawResponse);
  } else {
    return RequestResponse.fail(handleError('add_tag', response.error));
  }
}