private _delete()

in provisioning/service/src/provisioningserviceclient.ts [414:547]


  private _delete(endpointPrefix: string, enrollmentOrIdOrRegistration: string | any, etagOrCallback?: string | ErrorCallback, deleteCallback?: ErrorCallback): void {
    let ifMatch: string;
    let suppliedCallback: ErrorCallback | undefined;
    let id: string;

    suppliedCallback = deleteCallback || ((typeof etagOrCallback === 'function') ? etagOrCallback as ErrorCallback : undefined);
    if (!suppliedCallback) {
      throw new ArgumentError('No callback was passed.');
    }

    /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_015: [The `deleteIndividualEnrollment` method shall throw `ReferenceError` if the `enrollmentOrId` argument is falsy.] */
    /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_016: [The `deleteEnrollmentGroup` method shall throw `ReferenceError` if the `enrollmentGroupOrId` argument is falsy.] */
    /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_025: [The `deleteDeviceRegistrationState` method shall throw `ReferenceError` if the `idOrRegistrationState` argument is falsy.] */
    if (!enrollmentOrIdOrRegistration) {
      throw new ReferenceError('Required parameter \'' + enrollmentOrIdOrRegistration + '\' was null or undefined when calling delete.');
    }

    if (typeof enrollmentOrIdOrRegistration === 'string') {
      id = enrollmentOrIdOrRegistration;
      /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_040: [The `deleteIndividualEnrollment` method, if the first argument is a string, the second argument if present, must be a string or a callback, otherwise shall throw `ArgumentError`. .] */
      /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_045: [The `deleteEnrollmentGroup` method, if the first argument is a string, the second argument if present, must be a string or a callback, otherwise shall throw `ArgumentError`.] */
      /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_050: [The `deleteDeviceRegistrationState` method, if the first argument is a string, the second argument if present, must be a string or a callback, otherwise shall throw `ArgumentError`.] */
      if (!etagOrCallback) {
        ifMatch = undefined;
      } else if (typeof etagOrCallback === 'string') {
        /*Codes_**SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_044: [** The `deleteIndividualEnrollment` method, if the first argument is a string, and the second argument is a string, shall construct an HTTP request using information supplied by the caller as follows:
          DELETE /enrollments/<uri-encoded-enrollmentOrId>?api-version=<version> HTTP/1.1
          If-Match: <second argument>
          Authorization: <sharedAccessSignature>
          */
        /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_049: [** The `deleteEnrollmentGroup` method, if the first argument is a string, and the second argument is a string, shall construct an HTTP request using information supplied by the caller as follows:
          DELETE /enrollmentGroups/<uri-encoded-enrollmentGroupOrId>?api-version=<version> HTTP/1.1
          If-Match: <second argument>
          Authorization: <sharedAccessSignature>
          ] */
        /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_054: [** The `deleteDeviceRegistrationState` method, if the first argument is a string, and the second argument is a string, shall construct an HTTP request using information supplied by the caller as follows:
          DELETE /registrations/<uri-encoded-idOrRegistrationState>?api-version=<version> HTTP/1.1
          If-Match: <second argument>
          Authorization: <sharedAccessSignature>
          ] */
        ifMatch = etagOrCallback;
      } else if (typeof etagOrCallback === 'function') {
        /*Codes_**SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_043: [** The `deleteIndividualEnrollment` method, if the first argument is a string, and the second argument is NOT a string, shall construct an HTTP request using information supplied by the caller as follows:
          DELETE /enrollments/<uri-encoded-enrollmentOrId>?api-version=<version> HTTP/1.1
          Authorization: <sharedAccessSignature>
          */
        /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_048: [** The `deleteEnrollmentGroup` method, if the first argument is a string, and the second argument is NOT a string, shall construct an HTTP request using information supplied by the caller as follows:
          DELETE /enrollmentGroups/<uri-encoded-enrollmentGroupOrId>?api-version=<version> HTTP/1.1
          Authorization: <sharedAccessSignature>
          ] */
        /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_053: [** The `deleteDeviceRegistrationState` method, if the first argument is a string, and the second argument is NOT a string, shall construct an HTTP request using information supplied by the caller as follows:
          DELETE /registrations/<uri-encoded-idOrRegistrationState>?api-version=<version> HTTP/1.1
          Authorization: <sharedAccessSignature>
          ] */
        ifMatch = undefined;
        suppliedCallback = etagOrCallback;
      } else {
        throw new ArgumentError('Second argument of this delete method must be a string or function.');
      }
    } else {
      if (endpointPrefix === this._enrollmentsPrefix) {
        if (!enrollmentOrIdOrRegistration.registrationId) {
          /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_017: [The `deleteIndividualEnrollment` method, if the first argument is an `IndividualEnrollment` object, shall throw an `ArgumentError`, if the `registrationId` property is falsy.] */
          throw new ArgumentError('Required property \'registrationId\' was null or undefined when calling delete.');
        }
        id = enrollmentOrIdOrRegistration.registrationId;
      } else if (endpointPrefix === this._enrollmentGroupsPrefix) {
        if (!enrollmentOrIdOrRegistration.enrollmentGroupId) {
          /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_018: [The `deleteEnrollmentGroup` method, if the first argument is an `EnrollmentGroup` object, shall throw an `ArgumentError`, if the `enrollmentGroupId' property is falsy.] */
          throw new ArgumentError('Required property \'enrollmentGroupId\' was null or undefined when calling delete.');
        }
        id = enrollmentOrIdOrRegistration.enrollmentGroupId;
      } else if (endpointPrefix === this._registrationsPrefix) {
        if (!enrollmentOrIdOrRegistration.registrationId) {
          /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_026: [The `deleteDeviceRegistrationState` method, if the first argument is a `DeviceRegistrationState` object, shall throw an `ArgumentError`, if the `registrationId' property is falsy.] */
          throw new ArgumentError('Required property \'registrationId\' was null or undefined when calling delete.');
        }
        id = enrollmentOrIdOrRegistration.registrationId;
      } else {
        throw new ArgumentError('Invalid path specified for delete operation.');
      }

      if (enrollmentOrIdOrRegistration.etag) {
        /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_021: [The `deleteIndividualEnrollment` method, if the first argument is an `IndividualEnrollment` object, with a non-falsy `etag` property, shall construct an HTTP request using information supplied by the caller as follows:
          DELETE /enrollments/<uri-encoded-enrollmentOrIdOrRegistration.registrationId>?api-version=<version> HTTP/1.1
          If-Match: enrollmentOrIdOrRegistration.etag
          Authorization: <sharedAccessSignature>
          ] */
        /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_022: [The `deleteEnrollmentGroup` method, if the first argument is an `EnrollmentGroup` object, with a non-falsy `etag` property, shall construct an HTTP request using information supplied by the caller as follows:
          DELETE /enrollmentGroups/<uri-encoded-enrollmentGroupOrId.enrollmentGroupId>?api-version=<version> HTTP/1.1
          If-Match: enrollmentParameter.etag
          Authorization: <sharedAccessSignature>
          ] */
        /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_028: [** The `deleteDeviceRegistrationState` method, if the first argument is a `DeviceRegistrationState` object, with a non-falsy `etag` property, shall construct an HTTP request using information supplied by the caller as follows:
          DELETE /registrations/<uri-encoded-idOrRegistrationState.registrationId>?api-version=<version> HTTP/1.1
          If-Match: idOrRegistrationState.etag
          Authorization: <sharedAccessSignature>
          ] */
        ifMatch = enrollmentOrIdOrRegistration.etag;
      } else {
        /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_023: [The `deleteEnrollmentGroup` method, if the first argument is an `EnrollmentGroup` object, with a falsy `etag` property, shall construct an HTTP request using information supplied by the caller as follows:
          DELETE /enrollmentGroups/<uri-encoded-enrollmentGroupOrId.enrollmentGroupId>?api-version=<version> HTTP/1.1
          Authorization: <sharedAccessSignature>
          ] */
        /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_024: [The `deleteIndividualEnrollment` method, if the first argument is an `enrollment` object, with a falsy `etag` property, shall construct an HTTP request using information supplied by the caller as follows:
          DELETE /enrollments/<uri-encoded-enrollmentParameter.registrationId>?api-version=<version> HTTP/1.1
          Authorization: <sharedAccessSignature>
          ] */
        /*Codes_SRS_NODE_PROVISIONING_SERVICE_CLIENT_06_029: [** The `deleteDeviceRegistrationState` method, if the first argument is a `DeviceRegistrationState` object, with a falsy `etag` property, shall construct an HTTP request using information supplied by the caller as follows:
          DELETE /registrations/<uri-encoded-idOrRegistrationState.registrationId>?api-version=<version> HTTP/1.1
          Authorization: <sharedAccessSignature>
          ] */
        ifMatch = undefined;
      }
    }

    const path = endpointPrefix + encodeURIComponent(id) + this._versionQueryString();

    let httpHeaders = {};

    if (ifMatch) {
      httpHeaders['If-Match'] = ifMatch;
    }

    this._restApiClient.executeApiCall('DELETE', path, httpHeaders, null, (err) => {
      if (suppliedCallback) {
        if (err) {
          suppliedCallback(err);
        } else {
          suppliedCallback(null);
        }
      }
    });
  }