async update(id, title, description, categories, locations, event = {}) {
    const wishInfo = await this._getWishInfo(id);
    if (wishInfo.status !== PENDING) {
      throw new WishError('invalid-wish-status', 'only can update a pending wish');
    }

    const [allCategoryInfos, locationInfos] = await Promise.all([
      getUpdatedCategoryInfos(wishInfo.categories, categories),
      getUpdatedLocations(wishInfo.locations, locations),
    ]);

    const categoryInfos = getCustomPostCategoryInfos(allCategoryInfos);

    let data = {
      title: title,
      description: description,
      categories: categoryInfos,
      locations: locationInfos,
      updatedDateTime: firebase.firestore.FieldValue.serverTimestamp(),
    };

    // Events
    const hasEvent = Object.keys(event).length > 0;
    if (wishInfo.event === undefined && hasEvent) {
      // Setting event
      this._validateEvent(event);

      let newEvent = event;
      newEvent[event.key] = true;
      newEvent['createdDateTime'] = firebase.firestore.FieldValue.serverTimestamp();

      data['event'] = event;
    } else if (wishInfo.event !== undefined) {
      const isValidEventKey = event.key !== undefined && event.key !== '';
      if (hasEvent && isValidEventKey && event.key !== wishInfo.event.key) {
        throw new WishError('invalid-event-update', 'wish already has an existing event');
      }

      if (!hasEvent) {
        // Remove an event
        const event = firebase.firestore.FieldValue.delete();
        data['event'] = event;
      }
    }

    let wishDoc = wishesCollection.doc(id);
    await wishDoc.update(data);

    return wishDoc.get();
  }
/**
   * Update the fields of a wish. Does not include updating of status
   * @param {string} id The wish id
   * @param {string} title The wish title text
   * @param {string} description The wish description text
   * @param {array} categories A list of categories id that the wish belongs to
   * @param {array} locations A list of locations text that the wish belongs to
   * @param {string} event The event fields
   * @throws {WishError}
   * @throws {FirebaseError}
   * @return {object} A firebase document of the updated wish
   */
Update the fields of a wish.
Update the fields of a wish .
async update(id, title, description, categories, locations, event = {}) {
    const wishInfo = await this._getWishInfo(id);
    if (wishInfo.status !== PENDING) {
      throw new WishError('invalid-wish-status', 'only can update a pending wish');
    }
    const [allCategoryInfos, locationInfos] = await Promise.all([
      getUpdatedCategoryInfos(wishInfo.categories, categories),
      getUpdatedLocations(wishInfo.locations, locations),
    ]);
    const categoryInfos = getCustomPostCategoryInfos(allCategoryInfos);
    let data = {
      title: title,
      description: description,
      categories: categoryInfos,
      locations: locationInfos,
      updatedDateTime: firebase.firestore.FieldValue.serverTimestamp(),
    };
    const hasEvent = Object.keys(event).length > 0;
    if (wishInfo.event === undefined && hasEvent) {
      this._validateEvent(event);
      let newEvent = event;
      newEvent[event.key] = true;
      newEvent['createdDateTime'] = firebase.firestore.FieldValue.serverTimestamp();
      data['event'] = event;
    } else if (wishInfo.event !== undefined) {
      const isValidEventKey = event.key !== undefined && event.key !== '';
      if (hasEvent && isValidEventKey && event.key !== wishInfo.event.key) {
        throw new WishError('invalid-event-update', 'wish already has an existing event');
      }
      if (!hasEvent) {
        const event = firebase.firestore.FieldValue.delete();
        data['event'] = event;
      }
    }
    let wishDoc = wishesCollection.doc(id);
    await wishDoc.update(data);
    return wishDoc.get();
  }
async update ( id , title , description , categories , locations , event = { } ) { const wishInfo = await this . _getWishInfo ( id ) ; if ( wishInfo . status !== PENDING ) { throw new WishError ( 'invalid-wish-status' , 'only can update a pending wish' ) ; } const [ allCategoryInfos , locationInfos ] = await Promise . all ( [ getUpdatedCategoryInfos ( wishInfo . categories , categories ) , getUpdatedLocations ( wishInfo . locations , locations ) , ] ) ; const categoryInfos = getCustomPostCategoryInfos ( allCategoryInfos ) ; let data = { title : title , description : description , categories : categoryInfos , locations : locationInfos , updatedDateTime : firebase . firestore . FieldValue . serverTimestamp ( ) , } ; const hasEvent = Object . keys ( event ) . length > 0 ; if ( wishInfo . event === undefined && hasEvent ) { this . _validateEvent ( event ) ; let newEvent = event ; newEvent [ event . key ] = true ; newEvent [ 'createdDateTime' ] = firebase . firestore . FieldValue . serverTimestamp ( ) ; data [ 'event' ] = event ; } else if ( wishInfo . event !== undefined ) { const isValidEventKey = event . key !== undefined && event . key !== '' ; if ( hasEvent && isValidEventKey && event . key !== wishInfo . event . key ) { throw new WishError ( 'invalid-event-update' , 'wish already has an existing event' ) ; } if ( ! hasEvent ) { const event = firebase . firestore . FieldValue . delete ( ) ; data [ 'event' ] = event ; } } let wishDoc = wishesCollection . doc ( id ) ; await wishDoc . update ( data ) ; return wishDoc . get ( ) ; }
Update the fields of a wish.
Update the fields of a wish .
// Events // Setting event // Remove an event