准备角度发布请求

时间:2019-03-10 13:22:03

标签: angular rest

我正在研究一种基于角度的原型,该原型可以为SaaS(Zuora)后端提供数据。 我的原型可以在Zuora中创建新订单,并以反应性形式填写信息,以用于帐户信息等(基本上任何在POST请求中只需出现一次的信息)。但是我不知道如何在通话中添加“ n”个订阅(1 = <)。

目前,服务已部分硬编码: 通过服务发布功能:

 postOrders(orderStructure) {
    console.log('create Order');
    return this.http.post(ZUORA_URL + '/v1/orders/', orderStructure, {
      headers
    });
  }

在组件中创建函数

  createOrder() {
    const orderStructure = {
      existingAccountNumber: this.firstFormGroup.value.soldToControl[
        'Account Number'
      ],
      orderDate: formatDate(
        this.firstFormGroup.value.orderDate,
        'yyyy-MM-dd',
        'en'
      ),
      processingOptions: {
        billingOptions: {
          targetDate: '2019-08-01' // was ist das?
        },
        collectPayment: true,
        runBilling: true
      },
      subscriptions: [
        {
          orderActions: [
            {
              createSubscription: {
                subscribeToRatePlans: [
                  {
                    productRatePlanId: '8adce4216904fb6201690a1a15537188'
                  }
                ],
                terms: {
                  autoRenew: this.firstFormGroup.value.autorenew,
                  initialTerm: {
                    period: this.firstFormGroup.value.iterm,
                    periodType: this.firstFormGroup.value.itermPeriod,
                    startDate: formatDate(
                      this.firstFormGroup.value.termDate,
                      'yyyy-MM-dd',
                      'en'
                    ),
                    termType: 'TERMED'
                  },
                  renewalSetting: 'RENEW_WITH_SPECIFIC_TERM',
                  renewalTerms: [
                    {
                      period: this.firstFormGroup.value.rterm,
                      periodType: this.firstFormGroup.value.rtermPeriod
                    }
                  ]
                }
              },
              triggerDates: [
                {
                  name: 'ContractEffective',
                  triggerDate: formatDate(
                    this.firstFormGroup.value.triggerDate,
                    'yyyy-MM-dd',
                    'en'
                  )
                }
              ],
              type: 'CreateSubscription'
            }
          ]
        }
      ]
    };
    this.zuoraService.postOrders(orderStructure).subscribe(data => {
      console.log(data);
    });

如何将n个订单操作添加到订阅结构中?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

通过添加一个附加循环来预取订单获取而固定:

createOrder() {
    // Set the standard values if they haven't been changed
    if (this.firstFormGroup.value.rterm === '') {
      this.firstFormGroup.value.rterm = '12';
    }
    if (this.firstFormGroup.value.iterm === '') {
      this.firstFormGroup.value.iterm = '12';
    }
    if (!this.firstFormGroup.value.autorenew) {
      this.firstFormGroup.value.autorenew = 'false';
    }
    const subscriptions_cont = [];
    this.orderIntake.forEach(element => {
      const orderActions_cont =
        {
          orderActions: [
            {
              createSubscription: {
                subscribeToRatePlans: [
                  {
                    productRatePlanId: element.productRatePlans['id']
                  }
                ],
                terms: {
                  autoRenew: this.firstFormGroup.value.autorenew,
                  initialTerm: {
                    period: this.firstFormGroup.value.iterm,
                    periodType: this.firstFormGroup.value.itermPeriod,
                    startDate: formatDate(
                      this.firstFormGroup.value.termDate,
                      'yyyy-MM-dd',
                      'en'
                    ),
                    termType: 'TERMED'
                  },
                  renewalSetting: 'RENEW_WITH_SPECIFIC_TERM',
                  renewalTerms: [
                    {
                      period: 12,
                      periodType: 'Month'
                    }
                  ]
                }
              },
              triggerDates: [
                {
                  name: 'ContractEffective',
                  triggerDate: formatDate(
                    this.firstFormGroup.value.contractEffectiveDate,
                    'yyyy-MM-dd',
                    'en'
                  )
                },
                {
                  name: 'ServiceActivation',
                  triggerDate: formatDate(
                    this.firstFormGroup.value.serviceActivationDate,
                    'yyyy-MM-dd',
                    'en'
                  )
                },
                {
                  name: 'CustomerAcceptance',
                  triggerDate: formatDate(
                    this.firstFormGroup.value.customerAcceptanceDate,
                    'yyyy-MM-dd',
                    'en'
                  )
                }
              ],
              type: 'CreateSubscription'
            }
          ]
        };
      console.log('orderActions', orderActions_cont);
      subscriptions_cont.push(orderActions_cont);
      console.log('subscriptions zusammen', subscriptions_cont);
    });