ngrx entity adapter is not updating a sub property of a required property

771 views Asked by At

I have an object maintained in ngrx store like shown below -

{
 .
 .
 callStatus: ClientStatus;
 .
 .
}

and ClientStatus is a further nested interface like -

interface ClientStatus {
 status: boolean;
 csrObject: csrStatus;
}

now in an API response I am getting updated values of csrStatus for a single user type which I need to update. but when I try to -

adapter.updateOne(
{
  id: client.id,
  changes: { callStatus.csrObject: action.response }
})

I am getting error as I am not allowed to access a sub-property of a given key while updating.

Does anybody know how can I approach this problem?

1

There are 1 answers

0
satanTime On

I think you need to correct your code a bit:

adapter.updateOne({
    id: client.id,
    csrObject: action.response
  },
  state,
})

ngrx doc says the first argument is a Partial entity object the second argument is the state of the entity:

  on(UserActions.updateUser, (state, { update }) => {
    return adapter.updateOne(update, state);
  }),