Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This discovery details the code changes necessary for the search by phone to work in admin tool, and is based on the solution n. 1 proposed in Search customer by phone in Admin App.

...

The changes can be found in https://github.com/rbilabs/intl-admin-app/pull/242 .

Validate phone number updates

The user search, either by phone or emails, depends on the pk2 value of the user record in dynamo that necessarily has to have a phone number or an email, for example:

phone number:

...

email:

...

Therefore, we can only search a customer by phone number or email, but not both. Besides this issue, another problem is the update of the phone number. Today the change would only be reflected in user.details.phoneNumber and not in pk2 (check code below), which leads to the search by phone only working with the first number registered.

user-lookup-by-phone.repository.ts (https://github.com/rbilabs/intl-user-service/blob/master/src/users/user-lookup-by-phone.repository.ts#L103-L125)

Code Block
languagetypescript
  public async update(updatedUser: IUser): Promise<void> {
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    const { cognitoId, ...userItem } = updatedUser;

    let updateExpressions = DynamoDB.getUpdateExpressions(userItem);

    updateExpressions = {
      ...updateExpressions,
      ExpressionAttributeValues: {
        ...updateExpressions.ExpressionAttributeValues,
        [':phoneNumber']: updatedUser.details.phoneNumber,
      },
    };

    await this.dynamoClient
      .update({
        ...updateExpressions,
        ConditionExpression: '#details.phoneNumber = :phoneNumber',
        Key: { pk: updatedUser.cognitoId, sk: this.createSk() },
        TableName: this.tableName,
      })
      .promise();
  }

Deprecated

Necessary changes - summary

...