Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: #89 fixed comments related to remove key id
  • Loading branch information
daros10 committed Apr 22, 2020
commit b0b90d7954cd8cbd7ef4953e90ffd0393d5a66dd
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,10 @@ export class CreateCustomerComponent implements OnInit, OnDestroy {
}

onSubmit(customerData) {
const key = 'id';
if (this.customerToEdit) {
const customer = {
...customerData,
id: this.customerToEdit[key],
id: this.customerToEdit.id,
};
this.store.dispatch(new UpdateCustomer(customer));
this.customerForm.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,8 @@ export const initialState: CustomerState = {
customerIdToEdit: '',
};

export function customerManagementReducer(
state: CustomerState = initialState,
action: CustomerManagementActions
): CustomerState {
export const customerManagementReducer = (state: CustomerState = initialState, action: CustomerManagementActions) => {
const customersList = [...state.data];
const key = 'id';
switch (action.type) {
case CustomerManagementActionTypes.LOAD_CUSTOMERS: {
return {
Expand Down Expand Up @@ -76,7 +72,7 @@ export function customerManagementReducer(
}

case CustomerManagementActionTypes.DELETE_CUSTOMER_SUCCESS: {
const customers = state.data.filter((customer) => customer[key] !== action.customerId);
const customers = state.data.filter((customer) => customer.id !== action.customerId);
return {
...state,
data: customers,
Expand All @@ -102,7 +98,7 @@ export function customerManagementReducer(
}

case CustomerManagementActionTypes.UPDATE_CUSTOMER_SUCCESS: {
const index = customersList.findIndex((customer) => customer[key] === action.payload[key]);
const index = customersList.findIndex((customer) => customer.id === action.payload.id);
customersList[index] = action.payload;
return {
...state,
Expand Down Expand Up @@ -133,4 +129,4 @@ export function customerManagementReducer(
default:
return state;
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ export const customerIdtoEdit = createSelector(getCustomerState, (state: Custome
});

export const getCustomerById = createSelector(allCustomers, customerIdtoEdit, (customers, customerId) => {
const key = 'id';
return customers.find((customer) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could add the validation for (customers, customerId)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All changes were applied. @enriquezrene when you have a free time, please, check it.

return customer[key] === customerId;
return customer.id === customerId;
});
});
1 change: 1 addition & 0 deletions src/app/modules/shared/models/customer.model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface Customer {
id?: string;
name: string;
description?: string;
tenant_id: string;
Expand Down