Преглед изворни кода

feat(core): Create customer history entries for groups

Relates to #343
Michael Bromley пре 5 година
родитељ
комит
4620730af1

+ 2 - 1
packages/asset-server-plugin/e2e/graphql/generated-e2e-asset-server-plugin-types.ts

@@ -1278,10 +1278,11 @@ export enum HistoryEntryType {
     CUSTOMER_REGISTERED = 'CUSTOMER_REGISTERED',
     CUSTOMER_VERIFIED = 'CUSTOMER_VERIFIED',
     CUSTOMER_DETAIL_UPDATED = 'CUSTOMER_DETAIL_UPDATED',
+    CUSTOMER_ADDED_TO_GROUP = 'CUSTOMER_ADDED_TO_GROUP',
+    CUSTOMER_REMOVED_FROM_GROUP = 'CUSTOMER_REMOVED_FROM_GROUP',
     CUSTOMER_ADDRESS_CREATED = 'CUSTOMER_ADDRESS_CREATED',
     CUSTOMER_ADDRESS_UPDATED = 'CUSTOMER_ADDRESS_UPDATED',
     CUSTOMER_ADDRESS_DELETED = 'CUSTOMER_ADDRESS_DELETED',
-    CUSTOMER_ORDER_PLACED = 'CUSTOMER_ORDER_PLACED',
     CUSTOMER_PASSWORD_UPDATED = 'CUSTOMER_PASSWORD_UPDATED',
     CUSTOMER_PASSWORD_RESET_REQUESTED = 'CUSTOMER_PASSWORD_RESET_REQUESTED',
     CUSTOMER_PASSWORD_RESET_VERIFIED = 'CUSTOMER_PASSWORD_RESET_VERIFIED',

+ 2 - 1
packages/common/src/generated-shop-types.ts

@@ -919,10 +919,11 @@ export enum HistoryEntryType {
     CUSTOMER_REGISTERED = 'CUSTOMER_REGISTERED',
     CUSTOMER_VERIFIED = 'CUSTOMER_VERIFIED',
     CUSTOMER_DETAIL_UPDATED = 'CUSTOMER_DETAIL_UPDATED',
+    CUSTOMER_ADDED_TO_GROUP = 'CUSTOMER_ADDED_TO_GROUP',
+    CUSTOMER_REMOVED_FROM_GROUP = 'CUSTOMER_REMOVED_FROM_GROUP',
     CUSTOMER_ADDRESS_CREATED = 'CUSTOMER_ADDRESS_CREATED',
     CUSTOMER_ADDRESS_UPDATED = 'CUSTOMER_ADDRESS_UPDATED',
     CUSTOMER_ADDRESS_DELETED = 'CUSTOMER_ADDRESS_DELETED',
-    CUSTOMER_ORDER_PLACED = 'CUSTOMER_ORDER_PLACED',
     CUSTOMER_PASSWORD_UPDATED = 'CUSTOMER_PASSWORD_UPDATED',
     CUSTOMER_PASSWORD_RESET_REQUESTED = 'CUSTOMER_PASSWORD_RESET_REQUESTED',
     CUSTOMER_PASSWORD_RESET_VERIFIED = 'CUSTOMER_PASSWORD_RESET_VERIFIED',

+ 2 - 1
packages/common/src/generated-types.ts

@@ -1276,10 +1276,11 @@ export enum HistoryEntryType {
   CUSTOMER_REGISTERED = 'CUSTOMER_REGISTERED',
   CUSTOMER_VERIFIED = 'CUSTOMER_VERIFIED',
   CUSTOMER_DETAIL_UPDATED = 'CUSTOMER_DETAIL_UPDATED',
+  CUSTOMER_ADDED_TO_GROUP = 'CUSTOMER_ADDED_TO_GROUP',
+  CUSTOMER_REMOVED_FROM_GROUP = 'CUSTOMER_REMOVED_FROM_GROUP',
   CUSTOMER_ADDRESS_CREATED = 'CUSTOMER_ADDRESS_CREATED',
   CUSTOMER_ADDRESS_UPDATED = 'CUSTOMER_ADDRESS_UPDATED',
   CUSTOMER_ADDRESS_DELETED = 'CUSTOMER_ADDRESS_DELETED',
-  CUSTOMER_ORDER_PLACED = 'CUSTOMER_ORDER_PLACED',
   CUSTOMER_PASSWORD_UPDATED = 'CUSTOMER_PASSWORD_UPDATED',
   CUSTOMER_PASSWORD_RESET_REQUESTED = 'CUSTOMER_PASSWORD_RESET_REQUESTED',
   CUSTOMER_PASSWORD_RESET_VERIFIED = 'CUSTOMER_PASSWORD_RESET_VERIFIED',

+ 90 - 1
packages/core/e2e/customer-group.e2e-spec.ts

@@ -1,3 +1,4 @@
+import { pick } from '@vendure/common/lib/pick';
 import {
     AccountRegistrationEvent,
     EventBus,
@@ -19,13 +20,15 @@ import {
     DeleteCustomerGroup,
     GetCustomerGroup,
     GetCustomerGroups,
+    GetCustomerHistory,
     GetCustomerList,
     GetCustomerWithGroups,
+    HistoryEntryType,
     RemoveCustomersFromGroup,
     UpdateCustomerGroup,
 } from './graphql/generated-e2e-admin-types';
 import { DeletionResult } from './graphql/generated-e2e-shop-types';
-import { GET_CUSTOMER_LIST } from './graphql/shared-definitions';
+import { GET_CUSTOMER_HISTORY, GET_CUSTOMER_LIST } from './graphql/shared-definitions';
 import { assertThrowsWithMessage } from './utils/assert-throws-with-message';
 import { sortById } from './utils/test-order-utils';
 
@@ -67,6 +70,27 @@ describe('CustomerGroup resolver', () => {
         ]);
     });
 
+    it('history entry for CUSTOMER_ADDED_TO_GROUP after group created', async () => {
+        const { customer } = await adminClient.query<GetCustomerHistory.Query, GetCustomerHistory.Variables>(
+            GET_CUSTOMER_HISTORY,
+            {
+                id: customers[0].id,
+                options: {
+                    skip: 1,
+                },
+            },
+        );
+
+        expect(customer?.history.items.map(pick(['type', 'data']))).toEqual([
+            {
+                type: HistoryEntryType.CUSTOMER_ADDED_TO_GROUP,
+                data: {
+                    groupName: 'group 1',
+                },
+            },
+        ]);
+    });
+
     it('customerGroups', async () => {
         const { customerGroups } = await adminClient.query<
             GetCustomerGroups.Query,
@@ -141,6 +165,50 @@ describe('CustomerGroup resolver', () => {
         ]);
     });
 
+    it('history entry for CUSTOMER_ADDED_TO_GROUP not duplicated', async () => {
+        const { customer } = await adminClient.query<GetCustomerHistory.Query, GetCustomerHistory.Variables>(
+            GET_CUSTOMER_HISTORY,
+            {
+                id: customers[0].id,
+                options: {
+                    filter: {
+                        type: { eq: HistoryEntryType.CUSTOMER_ADDED_TO_GROUP },
+                    },
+                },
+            },
+        );
+
+        expect(customer?.history.items.map(pick(['type', 'data']))).toEqual([
+            {
+                type: HistoryEntryType.CUSTOMER_ADDED_TO_GROUP,
+                data: {
+                    groupName: 'group 1',
+                },
+            },
+        ]);
+    });
+
+    it('history entry for CUSTOMER_ADDED_TO_GROUP after customer added', async () => {
+        const { customer } = await adminClient.query<GetCustomerHistory.Query, GetCustomerHistory.Variables>(
+            GET_CUSTOMER_HISTORY,
+            {
+                id: customers[2].id,
+                options: {
+                    skip: 1,
+                },
+            },
+        );
+
+        expect(customer?.history.items.map(pick(['type', 'data']))).toEqual([
+            {
+                type: HistoryEntryType.CUSTOMER_ADDED_TO_GROUP,
+                data: {
+                    groupName: 'group 1 updated',
+                },
+            },
+        ]);
+    });
+
     it('customer.groups field resolver', async () => {
         const { customer } = await adminClient.query<
             GetCustomerWithGroups.Query,
@@ -180,6 +248,27 @@ describe('CustomerGroup resolver', () => {
         ]);
     });
 
+    it('history entry for CUSTOMER_REMOVED_FROM_GROUP', async () => {
+        const { customer } = await adminClient.query<GetCustomerHistory.Query, GetCustomerHistory.Variables>(
+            GET_CUSTOMER_HISTORY,
+            {
+                id: customers[1].id,
+                options: {
+                    skip: 2,
+                },
+            },
+        );
+
+        expect(customer?.history.items.map(pick(['type', 'data']))).toEqual([
+            {
+                type: HistoryEntryType.CUSTOMER_REMOVED_FROM_GROUP,
+                data: {
+                    groupName: 'group 1 updated',
+                },
+            },
+        ]);
+    });
+
     it('deleteCustomerGroup', async () => {
         const { deleteCustomerGroup } = await adminClient.query<
             DeleteCustomerGroup.Mutation,

+ 2 - 1
packages/core/e2e/graphql/generated-e2e-admin-types.ts

@@ -1278,10 +1278,11 @@ export enum HistoryEntryType {
     CUSTOMER_REGISTERED = 'CUSTOMER_REGISTERED',
     CUSTOMER_VERIFIED = 'CUSTOMER_VERIFIED',
     CUSTOMER_DETAIL_UPDATED = 'CUSTOMER_DETAIL_UPDATED',
+    CUSTOMER_ADDED_TO_GROUP = 'CUSTOMER_ADDED_TO_GROUP',
+    CUSTOMER_REMOVED_FROM_GROUP = 'CUSTOMER_REMOVED_FROM_GROUP',
     CUSTOMER_ADDRESS_CREATED = 'CUSTOMER_ADDRESS_CREATED',
     CUSTOMER_ADDRESS_UPDATED = 'CUSTOMER_ADDRESS_UPDATED',
     CUSTOMER_ADDRESS_DELETED = 'CUSTOMER_ADDRESS_DELETED',
-    CUSTOMER_ORDER_PLACED = 'CUSTOMER_ORDER_PLACED',
     CUSTOMER_PASSWORD_UPDATED = 'CUSTOMER_PASSWORD_UPDATED',
     CUSTOMER_PASSWORD_RESET_REQUESTED = 'CUSTOMER_PASSWORD_RESET_REQUESTED',
     CUSTOMER_PASSWORD_RESET_VERIFIED = 'CUSTOMER_PASSWORD_RESET_VERIFIED',

+ 2 - 1
packages/core/e2e/graphql/generated-e2e-shop-types.ts

@@ -919,10 +919,11 @@ export enum HistoryEntryType {
     CUSTOMER_REGISTERED = 'CUSTOMER_REGISTERED',
     CUSTOMER_VERIFIED = 'CUSTOMER_VERIFIED',
     CUSTOMER_DETAIL_UPDATED = 'CUSTOMER_DETAIL_UPDATED',
+    CUSTOMER_ADDED_TO_GROUP = 'CUSTOMER_ADDED_TO_GROUP',
+    CUSTOMER_REMOVED_FROM_GROUP = 'CUSTOMER_REMOVED_FROM_GROUP',
     CUSTOMER_ADDRESS_CREATED = 'CUSTOMER_ADDRESS_CREATED',
     CUSTOMER_ADDRESS_UPDATED = 'CUSTOMER_ADDRESS_UPDATED',
     CUSTOMER_ADDRESS_DELETED = 'CUSTOMER_ADDRESS_DELETED',
-    CUSTOMER_ORDER_PLACED = 'CUSTOMER_ORDER_PLACED',
     CUSTOMER_PASSWORD_UPDATED = 'CUSTOMER_PASSWORD_UPDATED',
     CUSTOMER_PASSWORD_RESET_REQUESTED = 'CUSTOMER_PASSWORD_RESET_REQUESTED',
     CUSTOMER_PASSWORD_RESET_VERIFIED = 'CUSTOMER_PASSWORD_RESET_VERIFIED',

+ 9 - 3
packages/core/e2e/shop-auth.e2e-spec.ts

@@ -375,7 +375,7 @@ describe('Shop auth & accounts', () => {
                     data: {},
                 },
                 {
-                    type: HistoryEntryType.CUSTOMER_PASSWORD_RESET_REQUESTED,
+                    type: HistoryEntryType.CUSTOMER_PASSWORD_RESET_VERIFIED,
                     data: {},
                 },
             ]);
@@ -530,11 +530,17 @@ describe('Shop auth & accounts', () => {
             expect(result.customer?.history.items.map(pick(['type', 'data']))).toEqual([
                 {
                     type: HistoryEntryType.CUSTOMER_EMAIL_UPDATE_REQUESTED,
-                    data: {},
+                    data: {
+                        newEmailAddress: 'new@address.com',
+                        oldEmailAddress: 'hayden.zieme12@hotmail.com',
+                    },
                 },
                 {
                     type: HistoryEntryType.CUSTOMER_EMAIL_UPDATE_VERIFIED,
-                    data: {},
+                    data: {
+                        newEmailAddress: 'new@address.com',
+                        oldEmailAddress: 'hayden.zieme12@hotmail.com',
+                    },
                 },
             ]);
         });

+ 27 - 5
packages/core/e2e/shop-customer.e2e-spec.ts

@@ -137,6 +137,28 @@ describe('Shop customers', () => {
             expect(result.updateCustomer.firstName).toBe('xyz');
         });
 
+        it('customer history for CUSTOMER_DETAIL_UPDATED', async () => {
+            const result = await adminClient.query<GetCustomerHistory.Query, GetCustomerHistory.Variables>(
+                GET_CUSTOMER_HISTORY,
+                {
+                    id: customer.id,
+                    options: {
+                        // skip populated CUSTOMER_ADDRESS_CREATED entry
+                        skip: 1,
+                    },
+                },
+            );
+
+            expect(result.customer?.history.items.map(pick(['type', 'data']))).toEqual([
+                {
+                    type: HistoryEntryType.CUSTOMER_DETAIL_UPDATED,
+                    data: {
+                        input: { firstName: 'xyz', id: 'T_1' },
+                    },
+                },
+            ]);
+        });
+
         it('createCustomerAddress works', async () => {
             const input: CreateAddressInput = {
                 streetLine1: '1 Test Street',
@@ -163,8 +185,8 @@ describe('Shop customers', () => {
                 {
                     id: customer.id,
                     options: {
-                        // skip populated CUSTOMER_ADDRESS_CREATED entry
-                        skip: 1,
+                        // skip populated CUSTOMER_ADDRESS_CREATED, CUSTOMER_DETAIL_UPDATED entries
+                        skip: 2,
                     },
                 },
             );
@@ -197,7 +219,7 @@ describe('Shop customers', () => {
         it('customer history for CUSTOMER_ADDRESS_UPDATED', async () => {
             const result = await adminClient.query<GetCustomerHistory.Query, GetCustomerHistory.Variables>(
                 GET_CUSTOMER_HISTORY,
-                { id: customer.id, options: { skip: 2 } },
+                { id: customer.id, options: { skip: 3 } },
             );
 
             expect(result.customer?.history.items.map(pick(['type', 'data']))).toEqual([
@@ -241,7 +263,7 @@ describe('Shop customers', () => {
         it('customer history for CUSTOMER_ADDRESS_DELETED', async () => {
             const result = await adminClient.query<GetCustomerHistory.Query, GetCustomerHistory.Variables>(
                 GET_CUSTOMER_HISTORY,
-                { id: customer.id, options: { skip: 3 } },
+                { id: customer.id, options: { skip: 4 } },
             );
 
             expect(result.customer?.history.items.map(pick(['type', 'data']))).toEqual([
@@ -290,7 +312,7 @@ describe('Shop customers', () => {
         it('customer history for CUSTOMER_PASSWORD_UPDATED', async () => {
             const result = await adminClient.query<GetCustomerHistory.Query, GetCustomerHistory.Variables>(
                 GET_CUSTOMER_HISTORY,
-                { id: customer.id, options: { skip: 4 } },
+                { id: customer.id, options: { skip: 5 } },
             );
 
             expect(result.customer?.history.items.map(pick(['type', 'data']))).toEqual([

+ 12 - 5
packages/core/src/api/resolvers/admin/customer-group.resolver.ts

@@ -42,8 +42,11 @@ export class CustomerGroupResolver {
 
     @Mutation()
     @Allow(Permission.CreateCustomer)
-    async createCustomerGroup(@Args() args: MutationCreateCustomerGroupArgs): Promise<CustomerGroup> {
-        return this.customerGroupService.create(args.input);
+    async createCustomerGroup(
+        @Ctx() ctx: RequestContext,
+        @Args() args: MutationCreateCustomerGroupArgs,
+    ): Promise<CustomerGroup> {
+        return this.customerGroupService.create(ctx, args.input);
     }
 
     @Mutation()
@@ -60,15 +63,19 @@ export class CustomerGroupResolver {
 
     @Mutation()
     @Allow(Permission.UpdateCustomer)
-    async addCustomersToGroup(@Args() args: MutationAddCustomersToGroupArgs): Promise<CustomerGroup> {
-        return this.customerGroupService.addCustomersToGroup(args);
+    async addCustomersToGroup(
+        @Ctx() ctx: RequestContext,
+        @Args() args: MutationAddCustomersToGroupArgs,
+    ): Promise<CustomerGroup> {
+        return this.customerGroupService.addCustomersToGroup(ctx, args);
     }
 
     @Mutation()
     @Allow(Permission.UpdateCustomer)
     async removeCustomersFromGroup(
+        @Ctx() ctx: RequestContext,
         @Args() args: MutationRemoveCustomersFromGroupArgs,
     ): Promise<CustomerGroup> {
-        return this.customerGroupService.removeCustomersFromGroup(args);
+        return this.customerGroupService.removeCustomersFromGroup(ctx, args);
     }
 }

+ 5 - 2
packages/core/src/api/resolvers/admin/customer.resolver.ts

@@ -51,9 +51,12 @@ export class CustomerResolver {
 
     @Mutation()
     @Allow(Permission.UpdateCustomer)
-    async updateCustomer(@Args() args: MutationUpdateCustomerArgs): Promise<Customer> {
+    async updateCustomer(
+        @Ctx() ctx: RequestContext,
+        @Args() args: MutationUpdateCustomerArgs,
+    ): Promise<Customer> {
         const { input } = args;
-        return this.customerService.update(input);
+        return this.customerService.update(ctx, input);
     }
 
     @Mutation()

+ 1 - 1
packages/core/src/api/resolvers/shop/shop-customer.resolver.ts

@@ -50,7 +50,7 @@ export class ShopCustomerResolver {
         @Args() args: MutationUpdateCustomerArgs,
     ): Promise<Customer> {
         const customer = await this.getCustomerForOwner(ctx);
-        return this.customerService.update({
+        return this.customerService.update(ctx, {
             id: customer.id,
             ...args.input,
         });

+ 2 - 1
packages/core/src/api/schema/type/history-entry.type.graphql

@@ -12,10 +12,11 @@ enum HistoryEntryType {
     CUSTOMER_REGISTERED
     CUSTOMER_VERIFIED
     CUSTOMER_DETAIL_UPDATED
+    CUSTOMER_ADDED_TO_GROUP
+    CUSTOMER_REMOVED_FROM_GROUP
     CUSTOMER_ADDRESS_CREATED
     CUSTOMER_ADDRESS_UPDATED
     CUSTOMER_ADDRESS_DELETED
-    CUSTOMER_ORDER_PLACED
     CUSTOMER_PASSWORD_UPDATED
     CUSTOMER_PASSWORD_RESET_REQUESTED
     CUSTOMER_PASSWORD_RESET_VERIFIED

+ 42 - 4
packages/core/src/service/services/customer-group.service.ts

@@ -6,6 +6,7 @@ import {
     CustomerListOptions,
     DeletionResponse,
     DeletionResult,
+    HistoryEntryType,
     MutationAddCustomersToGroupArgs,
     MutationRemoveCustomersFromGroupArgs,
     UpdateCustomerGroupInput,
@@ -13,6 +14,7 @@ import {
 import { ID, PaginatedList } from '@vendure/common/lib/shared-types';
 import { Connection } from 'typeorm';
 
+import { RequestContext } from '../../api/common/request-context';
 import { UserInputError } from '../../common/error/errors';
 import { assertFound, idsAreEqual } from '../../common/utils';
 import { CustomerGroup } from '../../entity/customer-group/customer-group.entity';
@@ -21,11 +23,14 @@ import { ListQueryBuilder } from '../helpers/list-query-builder/list-query-build
 import { getEntityOrThrow } from '../helpers/utils/get-entity-or-throw';
 import { patchEntity } from '../helpers/utils/patch-entity';
 
+import { HistoryService } from './history.service';
+
 @Injectable()
 export class CustomerGroupService {
     constructor(
         @InjectConnection() private connection: Connection,
         private listQueryBuilder: ListQueryBuilder,
+        private historyService: HistoryService,
     ) {}
 
     findAll(options?: CustomerGroupListOptions): Promise<PaginatedList<CustomerGroup>> {
@@ -48,13 +53,23 @@ export class CustomerGroupService {
             .then(([items, totalItems]) => ({ items, totalItems }));
     }
 
-    async create(input: CreateCustomerGroupInput): Promise<CustomerGroup> {
+    async create(ctx: RequestContext, input: CreateCustomerGroupInput): Promise<CustomerGroup> {
         const customerGroup = new CustomerGroup(input);
 
         const newCustomerGroup = await this.connection.getRepository(CustomerGroup).save(customerGroup);
         if (input.customerIds) {
             const customers = await this.getCustomersFromIds(input.customerIds);
-            customers.forEach((c) => (c.groups = [...(c.groups || []), newCustomerGroup]));
+            for (const customer of customers) {
+                customer.groups = [...(customer.groups || []), newCustomerGroup];
+                await this.historyService.createHistoryEntryForCustomer({
+                    ctx,
+                    customerId: customer.id,
+                    type: HistoryEntryType.CUSTOMER_ADDED_TO_GROUP,
+                    data: {
+                        groupName: customerGroup.name,
+                    },
+                });
+            }
             await this.connection.getRepository(Customer).save(customers);
         }
         return assertFound(this.findOne(newCustomerGroup.id));
@@ -82,19 +97,34 @@ export class CustomerGroupService {
         }
     }
 
-    async addCustomersToGroup(input: MutationAddCustomersToGroupArgs): Promise<CustomerGroup> {
+    async addCustomersToGroup(
+        ctx: RequestContext,
+        input: MutationAddCustomersToGroupArgs,
+    ): Promise<CustomerGroup> {
         const customers = await this.getCustomersFromIds(input.customerIds);
         const group = await getEntityOrThrow(this.connection, CustomerGroup, input.customerGroupId);
         for (const customer of customers) {
             if (!customer.groups.map((g) => g.id).includes(input.customerGroupId)) {
                 customer.groups.push(group);
+                await this.historyService.createHistoryEntryForCustomer({
+                    ctx,
+                    customerId: customer.id,
+                    type: HistoryEntryType.CUSTOMER_ADDED_TO_GROUP,
+                    data: {
+                        groupName: group.name,
+                    },
+                });
             }
         }
+
         await this.connection.getRepository(Customer).save(customers, { reload: false });
         return assertFound(this.findOne(group.id));
     }
 
-    async removeCustomersFromGroup(input: MutationRemoveCustomersFromGroupArgs): Promise<CustomerGroup> {
+    async removeCustomersFromGroup(
+        ctx: RequestContext,
+        input: MutationRemoveCustomersFromGroupArgs,
+    ): Promise<CustomerGroup> {
         const customers = await this.getCustomersFromIds(input.customerIds);
         const group = await getEntityOrThrow(this.connection, CustomerGroup, input.customerGroupId);
         for (const customer of customers) {
@@ -102,6 +132,14 @@ export class CustomerGroupService {
                 throw new UserInputError('error.customer-does-not-belong-to-customer-group');
             }
             customer.groups = customer.groups.filter((g) => !idsAreEqual(g.id, group.id));
+            await this.historyService.createHistoryEntryForCustomer({
+                ctx,
+                customerId: customer.id,
+                type: HistoryEntryType.CUSTOMER_REMOVED_FROM_GROUP,
+                data: {
+                    groupName: group.name,
+                },
+            });
         }
         await this.connection.getRepository(Customer).save(customers, { reload: false });
         return assertFound(this.findOne(group.id));

+ 42 - 8
packages/core/src/service/services/customer.service.ts

@@ -27,7 +27,6 @@ import { ConfigService } from '../../config/config.service';
 import { Address } from '../../entity/address/address.entity';
 import { CustomerGroup } from '../../entity/customer-group/customer-group.entity';
 import { Customer } from '../../entity/customer/customer.entity';
-import { Order } from '../../entity/order/order.entity';
 import { User } from '../../entity/user/user.entity';
 import { EventBus } from '../../event-bus/event-bus';
 import { AccountRegistrationEvent } from '../../event-bus/events/account-registration-event';
@@ -135,7 +134,24 @@ export class CustomerService {
         } else {
             this.eventBus.publish(new AccountRegistrationEvent(ctx, customer.user));
         }
-        return this.connection.getRepository(Customer).save(customer);
+        const createdCustomer = await await this.connection.getRepository(Customer).save(customer);
+
+        await this.historyService.createHistoryEntryForCustomer({
+            ctx,
+            customerId: createdCustomer.id,
+            type: HistoryEntryType.CUSTOMER_REGISTERED,
+            data: {},
+        });
+
+        if (customer.user?.verified) {
+            await this.historyService.createHistoryEntryForCustomer({
+                ctx,
+                customerId: createdCustomer.id,
+                type: HistoryEntryType.CUSTOMER_VERIFIED,
+                data: {},
+            });
+        }
+        return createdCustomer;
     }
 
     async registerCustomerAccount(ctx: RequestContext, input: RegisterCustomerInput): Promise<boolean> {
@@ -247,7 +263,7 @@ export class CustomerService {
             await this.historyService.createHistoryEntryForCustomer({
                 customerId: customer.id,
                 ctx,
-                type: HistoryEntryType.CUSTOMER_PASSWORD_RESET_REQUESTED,
+                type: HistoryEntryType.CUSTOMER_PASSWORD_RESET_VERIFIED,
                 data: {},
             });
             return customer;
@@ -271,11 +287,15 @@ export class CustomerService {
         if (!customer) {
             return false;
         }
+        const oldEmailAddress = customer.emailAddress;
         await this.historyService.createHistoryEntryForCustomer({
             customerId: customer.id,
             ctx,
             type: HistoryEntryType.CUSTOMER_EMAIL_UPDATE_REQUESTED,
-            data: {},
+            data: {
+                oldEmailAddress,
+                newEmailAddress,
+            },
         });
         if (this.configService.authOptions.requireVerification) {
             user.pendingIdentifier = newEmailAddress;
@@ -293,7 +313,10 @@ export class CustomerService {
                 customerId: customer.id,
                 ctx,
                 type: HistoryEntryType.CUSTOMER_EMAIL_UPDATE_VERIFIED,
-                data: {},
+                data: {
+                    oldEmailAddress,
+                    newEmailAddress,
+                },
             });
             return true;
         }
@@ -315,15 +338,26 @@ export class CustomerService {
             customerId: customer.id,
             ctx,
             type: HistoryEntryType.CUSTOMER_EMAIL_UPDATE_VERIFIED,
-            data: {},
+            data: {
+                oldEmailAddress: oldIdentifier,
+                newEmailAddress: customer.emailAddress,
+            },
         });
         return true;
     }
 
-    async update(input: UpdateCustomerInput): Promise<Customer> {
+    async update(ctx: RequestContext, input: UpdateCustomerInput): Promise<Customer> {
         const customer = await getEntityOrThrow(this.connection, Customer, input.id);
         const updatedCustomer = patchEntity(customer, input);
         await this.connection.getRepository(Customer).save(customer, { reload: false });
+        await this.historyService.createHistoryEntryForCustomer({
+            customerId: customer.id,
+            ctx,
+            type: HistoryEntryType.CUSTOMER_DETAIL_UPDATED,
+            data: {
+                input,
+            },
+        });
         return assertFound(this.findOne(customer.id));
     }
 
@@ -438,7 +472,7 @@ export class CustomerService {
         };
     }
 
-    async addNoteToCustomer(ctx: RequestContext, input: AddNoteToCustomerInput): Promise<Order> {
+    async addNoteToCustomer(ctx: RequestContext, input: AddNoteToCustomerInput): Promise<Customer> {
         const customer = await getEntityOrThrow(this.connection, Customer, input.id);
         await this.historyService.createHistoryEntryForCustomer(
             {

+ 14 - 2
packages/core/src/service/services/history.service.ts

@@ -29,6 +29,12 @@ export type CustomerHistoryEntryData = {
     [HistoryEntryType.CUSTOMER_ADDRESS_CREATED]: {
         address: string;
     };
+    [HistoryEntryType.CUSTOMER_ADDED_TO_GROUP]: {
+        groupName: string;
+    };
+    [HistoryEntryType.CUSTOMER_REMOVED_FROM_GROUP]: {
+        groupName: string;
+    };
     [HistoryEntryType.CUSTOMER_ADDRESS_UPDATED]: {
         address: string;
         input: UpdateAddressInput;
@@ -39,8 +45,14 @@ export type CustomerHistoryEntryData = {
     [HistoryEntryType.CUSTOMER_PASSWORD_UPDATED]: {};
     [HistoryEntryType.CUSTOMER_PASSWORD_RESET_REQUESTED]: {};
     [HistoryEntryType.CUSTOMER_PASSWORD_RESET_VERIFIED]: {};
-    [HistoryEntryType.CUSTOMER_EMAIL_UPDATE_REQUESTED]: {};
-    [HistoryEntryType.CUSTOMER_EMAIL_UPDATE_VERIFIED]: {};
+    [HistoryEntryType.CUSTOMER_EMAIL_UPDATE_REQUESTED]: {
+        oldEmailAddress: string;
+        newEmailAddress: string;
+    };
+    [HistoryEntryType.CUSTOMER_EMAIL_UPDATE_VERIFIED]: {
+        oldEmailAddress: string;
+        newEmailAddress: string;
+    };
     [HistoryEntryType.CUSTOMER_NOTE]: {
         note: string;
     };

+ 2 - 1
packages/elasticsearch-plugin/e2e/graphql/generated-e2e-elasticsearch-plugin-types.ts

@@ -1278,10 +1278,11 @@ export enum HistoryEntryType {
     CUSTOMER_REGISTERED = 'CUSTOMER_REGISTERED',
     CUSTOMER_VERIFIED = 'CUSTOMER_VERIFIED',
     CUSTOMER_DETAIL_UPDATED = 'CUSTOMER_DETAIL_UPDATED',
+    CUSTOMER_ADDED_TO_GROUP = 'CUSTOMER_ADDED_TO_GROUP',
+    CUSTOMER_REMOVED_FROM_GROUP = 'CUSTOMER_REMOVED_FROM_GROUP',
     CUSTOMER_ADDRESS_CREATED = 'CUSTOMER_ADDRESS_CREATED',
     CUSTOMER_ADDRESS_UPDATED = 'CUSTOMER_ADDRESS_UPDATED',
     CUSTOMER_ADDRESS_DELETED = 'CUSTOMER_ADDRESS_DELETED',
-    CUSTOMER_ORDER_PLACED = 'CUSTOMER_ORDER_PLACED',
     CUSTOMER_PASSWORD_UPDATED = 'CUSTOMER_PASSWORD_UPDATED',
     CUSTOMER_PASSWORD_RESET_REQUESTED = 'CUSTOMER_PASSWORD_RESET_REQUESTED',
     CUSTOMER_PASSWORD_RESET_VERIFIED = 'CUSTOMER_PASSWORD_RESET_VERIFIED',

Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
schema-admin.json


Разлика између датотеке није приказан због своје велике величине
+ 0 - 0
schema-shop.json


Неке датотеке нису приказане због велике количине промена