如何循环遍历表单数组并发布它?

时间:2019-10-22 10:33:28

标签: angular typescript observable angular8

我需要遍历表单数组以获取患者数据并将其发布。为了能够发布数据,我需要获取正确的ID来维护数据库的结构。

我试图进行单独的帖子调用,但由于要先调用正确的键,因此无法解决。

我需要第二个switchMap的帮助,我想在其中循环遍历表单数组以设置值并将其发布到数据库。


    this.PatQue.doctorQuePatientQueControllerFindById(IDdrQue, ({ "include": [{"relation": "patientQue" }] })).pipe(
          // First switchMap is used to extract the patientQue.id and also set the model for CheckIn object and POST it to backend
          switchMap((data) => {
            console.log("Patient que and doctor que testing: " + JSON.stringify(data));
            // Declaring the model which will host the body of the patient and setting the initial value
            let test: NewCheckInInDoctorQue = { displayName: this.getFirstName(0) };

            // Setting rest of the values
            test.checkInTime = this.datePipe.transform(new Date(), 'h:MM:ss');
            test.patientQueId = data.id;
            test.status = "Checkedin";

            return this.PatQueCheckin.patientQueCheckInControllerCreate(data.id, test);
          }),
          // Second switchMap is used to set the model for Patient CheckIn and also get the checkIn.id and POST it to backend
          switchMap((data1) => {
            console.log("Second switchMap: " + JSON.stringify(data1));

            // Declaring the model PatientPartial
            let test: NewPatientInCheckIn = { firstName: this.getFirstName(0), lastName: this.getLastName(0),
                        dob: this.datePipe.transform(this.getDOB(0), 'yyyy-MM-dd') };

            // Setting the values
            test.checkInId = data1.id;
            this.checkinID = data1.id;      // CheckIn id is stored to used later when needed

            return this.PatCheckIn.checkInPatientControllerCreate(data1.id, test);
          }),
          // Thrid switchMap is used to set the model for Reminder and use the checkIn.id to POST reminder to backend
          switchMap((data2) => {
            console.log("Third switchMap:" + JSON.stringify(data2));

            // Declaring the model newReminderInCheckIn
            let test: NewReminderInCheckIn = { checkInId: data2.checkInId };

            // Setting values
            test.isEnable = this.textboxDisabled;

            if (test.isEnable) {
              test.email = this.notificationForm.controls['email'].value;
              test.phone = this.notificationForm.controls['phone'].value;
            }

            console.log("Test from 3rd switchMap: " + JSON.stringify(test));

            return this.ReminderCheckin.checkInReminderControllerCreate(data2.checkInId, test);
          })
        ).subscribe(data => {
          console.log("After Reminder data: " + JSON.stringify(data));
        }, error => {
          console.log("Error: " + error);
        });

0 个答案:

没有答案