src/rest.js
// Returns a promise that doesn't resolve to any useful value.
Returns a promise that doesn't resolve to any useful value.
Returns a promise that doesn ' t resolve to any useful value .
function del(config, auth, className, objectId, clientSDK) {
  if (typeof objectId !== 'string') {
    throw new Parse.Error(Parse.Error.INVALID_JSON,
                          'bad objectId');
  }
  if (className === '_User' && !auth.couldUpdateUserId(objectId)) {
    throw new Parse.Error(Parse.Error.SESSION_MISSING,
                          'insufficient auth to delete user');
  }
  enforceRoleSecurity('delete', className, auth);
  var inflatedObject;
  return Promise.resolve().then(() => {
    if (className !== '_User') {
      return;
    }
    let orQueries = [];
    orQueries.push({user1Id: objectId});
    orQueries.push({user2Id: objectId});
    return config.database.deleteManyByQuery('swipe', {'$or': orQueries});
  }).then(() => {
    if (className !== '_User') {
      return;
    }
    let orQueries = [];
    orQueries.push({user1Id: objectId});
    orQueries.push({user2Id: objectId});
    return config.database.deleteManyByQuery('match', {'$or': orQueries});
  }).then(() => {
    if (triggers.getTrigger(className, triggers.Types.beforeDelete, config.applicationId) ||
        triggers.getTrigger(className, triggers.Types.afterDelete, config.applicationId) ||
        (config.liveQueryController && config.liveQueryController.hasLiveQuery(className)) ||
        className === '_Session') {
      return find(config, Auth.master(config), className, {objectId: objectId})
      .then((response) => {
        if (response && response.results && response.results.length) {
          const firstResult = response.results[0];
          firstResult.className = className;
          if (className === '_Session' && !auth.isMaster) {
            if (!auth.user || firstResult.user.objectId !== auth.user.id) {
              throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'invalid session token');
            }
          }
          if (className === '_Session') {
            var cacheAdapter = config.cacheController;
            cacheAdapter.user.del(firstResult.sessionToken);
          }
          inflatedObject = Parse.Object.fromJSON(firstResult);
          config.liveQueryController.onAfterDelete(inflatedObject.className, inflatedObject);
          return triggers.maybeRunTrigger(triggers.Types.beforeDelete, auth, inflatedObject, null,  config);
        }
        throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND,
                              'Object not found for delete.');
      });
    }
    return Promise.resolve({});
  }).then(() => {
    if (!auth.isMaster) {
      return auth.getUserRoles();
    } else {
      return;
    }
  }).then(() => {
    var options = {};
    if (!auth.isMaster) {
      options.acl = ['*'];
      if (auth.user) {
        options.acl.push(auth.user.id);
        options.acl = options.acl.concat(auth.userRoles);
      }
    }
    return config.database.destroy(className, {
      objectId: objectId
    }, options);
  }).then(() => {
    return triggers.maybeRunTrigger(triggers.Types.afterDelete, auth, inflatedObject, null, config);
  });
}
function del ( config , auth , className , objectId , clientSDK ) { if ( typeof objectId !== 'string' ) { throw new Parse . Error ( Parse . Error . INVALID_JSON , 'bad objectId' ) ; } if ( className === '_User' && ! auth . couldUpdateUserId ( objectId ) ) { throw new Parse . Error ( Parse . Error . SESSION_MISSING , 'insufficient auth to delete user' ) ; } enforceRoleSecurity ( 'delete' , className , auth ) ; var inflatedObject ; return Promise . resolve ( ) . then ( ( ) => { if ( className !== '_User' ) { return ; } let orQueries = [ ] ; orQueries . push ( { user1Id : objectId } ) ; orQueries . push ( { user2Id : objectId } ) ; return config . database . deleteManyByQuery ( 'swipe' , { '$or' : orQueries } ) ; } ) . then ( ( ) => { if ( className !== '_User' ) { return ; } let orQueries = [ ] ; orQueries . push ( { user1Id : objectId } ) ; orQueries . push ( { user2Id : objectId } ) ; return config . database . deleteManyByQuery ( 'match' , { '$or' : orQueries } ) ; } ) . then ( ( ) => { if ( triggers . getTrigger ( className , triggers . Types . beforeDelete , config . applicationId ) || triggers . getTrigger ( className , triggers . Types . afterDelete , config . applicationId ) || ( config . liveQueryController && config . liveQueryController . hasLiveQuery ( className ) ) || className === '_Session' ) { return find ( config , Auth . master ( config ) , className , { objectId : objectId } ) . then ( ( response ) => { if ( response && response . results && response . results . length ) { const firstResult = response . results [ 0 ] ; firstResult . className = className ; if ( className === '_Session' && ! auth . isMaster ) { if ( ! auth . user || firstResult . user . objectId !== auth . user . id ) { throw new Parse . Error ( Parse . Error . INVALID_SESSION_TOKEN , 'invalid session token' ) ; } } if ( className === '_Session' ) { var cacheAdapter = config . cacheController ; cacheAdapter . user . del ( firstResult . sessionToken ) ; } inflatedObject = Parse . Object . fromJSON ( firstResult ) ; config . liveQueryController . onAfterDelete ( inflatedObject . className , inflatedObject ) ; return triggers . maybeRunTrigger ( triggers . Types . beforeDelete , auth , inflatedObject , null , config ) ; } throw new Parse . Error ( Parse . Error . OBJECT_NOT_FOUND , 'Object not found for delete.' ) ; } ) ; } return Promise . resolve ( { } ) ; } ) . then ( ( ) => { if ( ! auth . isMaster ) { return auth . getUserRoles ( ) ; } else { return ; } } ) . then ( ( ) => { var options = { } ; if ( ! auth . isMaster ) { options . acl = [ '*' ] ; if ( auth . user ) { options . acl . push ( auth . user . id ) ; options . acl = options . acl . concat ( auth . userRoles ) ; } } return config . database . destroy ( className , { objectId : objectId } , options ) ; } ) . then ( ( ) => { return triggers . maybeRunTrigger ( triggers . Types . afterDelete , auth , inflatedObject , null , config ) ; } ) ; }
Returns a promise that doesn't resolve to any useful value.
Returns a promise that doesn ' t resolve to any useful value .
// Notify LiveQuery server if possible