#angular #rest
#angular #rest
Вопрос:
Я работаю над прототипом на основе angular, который поддерживает SaaS (Zuora) Серверная часть. Мой прототип может создавать новые заказы в Zuora с информацией, заполненной в реактивной форме для информации об учетной записи и т.д. (в основном все, что просто должно появиться один раз в запросе POST). Но я понятия не имею, как добавить «n» (1 = <) подписок на вызов.
На данный момент сервис частично жестко запрограммирован: функция Post из сервиса:
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 orderactions в структуру подписки?
спасибо, что помогли мне!
Ответ №1:
исправлено путем добавления дополнительного цикла для предварительной выборки при приеме заказа:
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);
});