mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-28 22:42:11 +01:00
Merged PR 462: #1386 Adressuebergabe bei Online- und Gastkunde angepasst
#1386 Adressuebergabe bei Online- und Gastkunde angepasst
This commit is contained in:
@@ -14,6 +14,7 @@ import {
|
||||
ResponseArgsOfIEnumerableOfBonusCardInfoDTO,
|
||||
ShippingAddressDTO,
|
||||
} from '@swagger/crm';
|
||||
import { isArray } from '@utils/common';
|
||||
import { PagedResult, Result } from 'apps/domain/defs/src/public-api';
|
||||
import { Observable, of, ReplaySubject } from 'rxjs';
|
||||
import { catchError, map, mergeMap, retry } from 'rxjs/operators';
|
||||
@@ -59,11 +60,87 @@ export class CrmCustomerService {
|
||||
}
|
||||
|
||||
createOnlineCustomer(customer: CustomerDTO): Observable<Result<CustomerDTO>> {
|
||||
return this.customerService.CustomerCreateOnlineCustomer({ ...customer, customerType: 8, hasOnlineAccount: true });
|
||||
const payload: CustomerDTO = { ...customer, customerType: 8, hasOnlineAccount: true };
|
||||
|
||||
if (!(isArray(payload.shippingAddresses) && payload.shippingAddresses.length > 0)) {
|
||||
payload.shippingAddresses = [
|
||||
{
|
||||
data: {
|
||||
address: payload.address,
|
||||
communicationDetails: payload.communicationDetails,
|
||||
firstName: payload.firstName,
|
||||
gender: payload.gender,
|
||||
lastName: payload.lastName,
|
||||
organisation: payload.organisation,
|
||||
title: payload.title,
|
||||
type: 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (!(isArray(payload.payers) && payload.payers.length > 0)) {
|
||||
payload.payers = [
|
||||
{
|
||||
payer: {
|
||||
data: {
|
||||
address: payload.address,
|
||||
communicationDetails: payload.communicationDetails,
|
||||
firstName: payload.firstName,
|
||||
gender: payload.gender,
|
||||
lastName: payload.lastName,
|
||||
organisation: payload.organisation,
|
||||
title: payload.title,
|
||||
payerType: payload.customerType,
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
return this.customerService.CustomerCreateOnlineCustomer(payload);
|
||||
}
|
||||
|
||||
createGuestCustomer(customer: CustomerDTO): Observable<Result<CustomerDTO>> {
|
||||
return this.customerService.CustomerCreateOnlineCustomer({ ...customer, customerType: 8, isGuestAccount: true });
|
||||
const payload: CustomerDTO = { ...customer, customerType: 8, isGuestAccount: true };
|
||||
|
||||
if (!(isArray(payload.shippingAddresses) && payload.shippingAddresses.length > 0)) {
|
||||
payload.shippingAddresses = [
|
||||
{
|
||||
data: {
|
||||
address: payload.address,
|
||||
communicationDetails: payload.communicationDetails,
|
||||
firstName: payload.firstName,
|
||||
gender: payload.gender,
|
||||
lastName: payload.lastName,
|
||||
organisation: payload.organisation,
|
||||
title: payload.title,
|
||||
type: 1,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
if (!(isArray(payload.payers) && payload.payers.length > 0)) {
|
||||
payload.payers = [
|
||||
{
|
||||
payer: {
|
||||
data: {
|
||||
address: payload.address,
|
||||
communicationDetails: payload.communicationDetails,
|
||||
firstName: payload.firstName,
|
||||
gender: payload.gender,
|
||||
lastName: payload.lastName,
|
||||
organisation: payload.organisation,
|
||||
title: payload.title,
|
||||
payerType: payload.customerType,
|
||||
},
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
return this.customerService.CustomerCreateOnlineCustomer(payload);
|
||||
}
|
||||
|
||||
createBranchCustomer(customer: CustomerDTO): Observable<Result<CustomerDTO>> {
|
||||
|
||||
@@ -127,7 +127,18 @@ export class CustomerCreateGuestComponent extends CustomerCreateComponentBase im
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await this.customerService.createGuestCustomer(this.control.value).toPromise();
|
||||
let newCustomer: CustomerDTO = this.control.value;
|
||||
if (this.control.value.differentShippingAddress) {
|
||||
newCustomer.shippingAddresses = [
|
||||
{
|
||||
data: {
|
||||
...this.control.value.shippingAddress,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
const response = await this.customerService.createGuestCustomer(newCustomer).toPromise();
|
||||
|
||||
if (this.control.value.differentShippingAddress) {
|
||||
try {
|
||||
|
||||
@@ -148,23 +148,18 @@ export class CustomerCreateOnlineComponent extends CustomerCreateComponentBase i
|
||||
newCustomer = { ...newCustomer, ...this.upgradeCustomer };
|
||||
}
|
||||
|
||||
const response = await this.customerService.createOnlineCustomer(newCustomer).toPromise();
|
||||
|
||||
if (this.control.value.differentShippingAddress) {
|
||||
try {
|
||||
const shippingResponse = await this.customerService
|
||||
.createShippingAddress(response.result.id, this.control.value.shippingAddress, true)
|
||||
.toPromise();
|
||||
if (shippingResponse.error) {
|
||||
throw new Error(shippingResponse.message);
|
||||
}
|
||||
} catch (error) {
|
||||
this.control.enable();
|
||||
console.error(error);
|
||||
return;
|
||||
}
|
||||
newCustomer.shippingAddresses = [
|
||||
{
|
||||
data: {
|
||||
...this.control.value.shippingAddress,
|
||||
},
|
||||
},
|
||||
];
|
||||
}
|
||||
|
||||
const response = await this.customerService.createOnlineCustomer(newCustomer).toPromise();
|
||||
|
||||
if (response.error) {
|
||||
throw new Error(response.message);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user