Skip to content

Commit b0b90d7

Browse files
committed
fix: #89 fixed comments related to remove key id
1 parent dd5446f commit b0b90d7

File tree

4 files changed

+7
-12
lines changed

4 files changed

+7
-12
lines changed

src/app/modules/customer-management/components/customer-info/components/create-customer/create-customer.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
5454
}
5555

5656
onSubmit(customerData) {
57-
const key = 'id';
5857
if (this.customerToEdit) {
5958
const customer = {
6059
...customerData,
61-
id: this.customerToEdit[key],
60+
id: this.customerToEdit.id,
6261
};
6362
this.store.dispatch(new UpdateCustomer(customer));
6463
this.customerForm.reset();

src/app/modules/customer-management/store/customer-management.reducers.ts

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,8 @@ export const initialState: CustomerState = {
1515
customerIdToEdit: '',
1616
};
1717

18-
export function customerManagementReducer(
19-
state: CustomerState = initialState,
20-
action: CustomerManagementActions
21-
): CustomerState {
18+
export const customerManagementReducer = (state: CustomerState = initialState, action: CustomerManagementActions) => {
2219
const customersList = [...state.data];
23-
const key = 'id';
2420
switch (action.type) {
2521
case CustomerManagementActionTypes.LOAD_CUSTOMERS: {
2622
return {
@@ -76,7 +72,7 @@ export function customerManagementReducer(
7672
}
7773

7874
case CustomerManagementActionTypes.DELETE_CUSTOMER_SUCCESS: {
79-
const customers = state.data.filter((customer) => customer[key] !== action.customerId);
75+
const customers = state.data.filter((customer) => customer.id !== action.customerId);
8076
return {
8177
...state,
8278
data: customers,
@@ -102,7 +98,7 @@ export function customerManagementReducer(
10298
}
10399

104100
case CustomerManagementActionTypes.UPDATE_CUSTOMER_SUCCESS: {
105-
const index = customersList.findIndex((customer) => customer[key] === action.payload[key]);
101+
const index = customersList.findIndex((customer) => customer.id === action.payload.id);
106102
customersList[index] = action.payload;
107103
return {
108104
...state,
@@ -133,4 +129,4 @@ export function customerManagementReducer(
133129
default:
134130
return state;
135131
}
136-
}
132+
};

src/app/modules/customer-management/store/customer-management.selectors.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ export const customerIdtoEdit = createSelector(getCustomerState, (state: Custome
1818
});
1919

2020
export const getCustomerById = createSelector(allCustomers, customerIdtoEdit, (customers, customerId) => {
21-
const key = 'id';
2221
return customers.find((customer) => {
23-
return customer[key] === customerId;
22+
return customer.id === customerId;
2423
});
2524
});

src/app/modules/shared/models/customer.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export interface Customer {
2+
id?: string;
23
name: string;
34
description?: string;
45
tenant_id: string;

0 commit comments

Comments
 (0)