|
@@ -246,6 +246,10 @@ export class CustomerService {
|
|
|
const hasEmailAddress = (i: any): i is UpdateCustomerInput & { emailAddress: string } =>
|
|
const hasEmailAddress = (i: any): i is UpdateCustomerInput & { emailAddress: string } =>
|
|
|
Object.hasOwnProperty.call(i, 'emailAddress');
|
|
Object.hasOwnProperty.call(i, 'emailAddress');
|
|
|
|
|
|
|
|
|
|
+ const customer = await this.connection.getEntityOrThrow(ctx, Customer, input.id, {
|
|
|
|
|
+ channelId: ctx.channelId,
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
if (hasEmailAddress(input)) {
|
|
if (hasEmailAddress(input)) {
|
|
|
const existingCustomerInChannel = await this.connection
|
|
const existingCustomerInChannel = await this.connection
|
|
|
.getRepository(ctx, Customer)
|
|
.getRepository(ctx, Customer)
|
|
@@ -260,11 +264,23 @@ export class CustomerService {
|
|
|
if (existingCustomerInChannel) {
|
|
if (existingCustomerInChannel) {
|
|
|
return new EmailAddressConflictAdminError();
|
|
return new EmailAddressConflictAdminError();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ if (customer.user) {
|
|
|
|
|
+ const existingUserWithEmailAddress = await this.userService.getUserByEmailAddress(
|
|
|
|
|
+ ctx,
|
|
|
|
|
+ input.emailAddress,
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ if (
|
|
|
|
|
+ existingUserWithEmailAddress &&
|
|
|
|
|
+ !idsAreEqual(customer.user.id, existingUserWithEmailAddress.id)
|
|
|
|
|
+ ) {
|
|
|
|
|
+ return new EmailAddressConflictAdminError();
|
|
|
|
|
+ }
|
|
|
|
|
+ await this.userService.changeNativeIdentifier(ctx, customer.user.id, input.emailAddress);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const customer = await this.connection.getEntityOrThrow(ctx, Customer, input.id, {
|
|
|
|
|
- channelId: ctx.channelId,
|
|
|
|
|
- });
|
|
|
|
|
const updatedCustomer = patchEntity(customer, input);
|
|
const updatedCustomer = patchEntity(customer, input);
|
|
|
await this.connection.getRepository(ctx, Customer).save(updatedCustomer, { reload: false });
|
|
await this.connection.getRepository(ctx, Customer).save(updatedCustomer, { reload: false });
|
|
|
await this.customFieldRelationService.updateRelations(ctx, Customer, input, updatedCustomer);
|
|
await this.customFieldRelationService.updateRelations(ctx, Customer, input, updatedCustomer);
|