elizabethrakhibaby / DabaoBuddy

An interactive app that aims to establish a takeaway system within the NUS campus that benefits both time-pressed students in need of quick meals and financially independent students seeking opportunities to earn allowances via delivery services.
0 stars 1 forks source link

Problem with Order Placement #27

Closed elizabethrakhibaby closed 1 year ago

elizabethrakhibaby commented 1 year ago

Issue with createOrder() function in ConfirmOrderScreen

FirebaseError: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined (found in field location in document orderList/ZzAz5AOJiF1JQ07FOZ4l) FirebaseError: [code=invalid-argument]: Function DocumentReference.set() called with invalid data. Unsupported field value: undefined (found in field location in document orderList/ZzAz5AOJiF1JQ07FOZ4l)

elizabethrakhibaby commented 1 year ago

Need to ensure that all the fields in the orderData object have valid values. The error message specifically mentions that the location field has an unsupported value of undefined. If any of the fields are optional and can legitimately have undefined values, consider adding conditional checks before including them in the orderData object. For example, you can use the optional chaining operator ?. to handle optional fields. ` // Add conditional checks for optional fields const location = userData.location || 'Default Location'; const address = userData.address || 'Default Address'; const imageURLOfFoodItem = userData.imageURL || 'Default Image URL'; const overallRating = userData.rating || 0; const priceOfItem = userData.price || 0; const storeID = userData.storeID || 'Default Store ID'; const storeName = userData.storeName || 'Default Store Name';

    const orderData = {
        address,
        imageURLOfFoodItem,
        overallRating,
        priceOfItem,
        storeID,
        storeName,
        placedUserID: uid,
        placedUserName,
        acceptedUserID: null,
        acceptedUserName: null,
        location,
    };`