如何根据从数据库中获取的值在Firebase中编写更新查询和插入查询?

时间:2019-05-03 10:14:59

标签: angular typescript firebase google-cloud-firestore

有一个用于输入名称,数量的产品的用户界面。如果数据库中已经存在产品名称,则从数据库值中减去我们输入的产品数量,并更新其中具有相同产品数量字段的产品。否则将其插入。

if(this.storeservice.checkoutgoing(name))
      {

      this.storeservice.checkoutgoing(name).valueChanges().subscribe((arg: any) =>
       {


        arg.forEach(elem => {
          const id = elem.id;
          const prd = elem.productqty;
         // const fieldprd =  element.incomingpieces;

           const total: number  = Number.parseFloat(prd.toString()) -  Number.parseFloat(outgoingpieces.toString());

          this.storeservice.updateoutgoingo(total,id);
     });

      });

    }
    else
    {

    }







checkoutgoing(name) : AngularFirestoreCollection<any> {
    return this.db.collection(`productmetirials`, ref => ref.where('productname','==',name).orderBy("date", "desc"));
  }



  updateoutgoingo(productqty,id):  Promise<void> {

    const date: string  = new Date().toISOString();
    const method = 'outgoing';

    return this.db.doc(`productmeterials/${id}`).update({
      productqty,
        date,

      });[enter image description here][1]

    }

0 个答案:

没有答案