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.
POC
Validate SA market solution
In
Jira Legacy | ||||||
---|---|---|---|---|---|---|
|
Result:
After confirming that SA market is deployed in eu-central-1 AWS Region, I could find lookup records created in Dynamo:
...
With this information, I was able to validate that the search could work in admin app:
Note |
---|
Since this is just a proof of concept, the example is not working perfectly. For example, the search bar is not showing the customer name and the phone in Customer Details page is wrong but this issues would be fixed during the development. |
Searching by phone
Result
...
Code changes
In this section are listed the changes made for this validation in intl-packages and intl-admin-app repositories.
intl-packages:
users.ts:
Code Block | ||
---|---|---|
| ||
public getByPhoneNumber(
phoneNumber: string,
searchByUserServiceLookup = false,
): Promise<IUserItem | undefined> {
return searchByUserServiceLookup
? this.usersDynamo.getByUserServicePhoneLookup(phoneNumber)
: this.usersDynamo.getByPhoneNumber(phoneNumber);
} |
users-dynamo.ts:
Code Block |
---|
public async getByUserServicePhoneLookup(phoneNumber: string): Promise<IUserItem | undefined> {
const lookupItem = await this.userLookupByPhone.getByUserServiceLookup(phoneNumber);
if (lookupItem) {
if (lookupItem) {
const cognitoId = lookupItem.pk;
const user = await this.getById(cognitoId);
return user;
}
}
return undefined;
} |
user-lookup-by-phone:
Code Block |
---|
public async getByUserServiceLookup(
phoneNumber: string,
): Promise<IUserLookupByPhone | undefined> {
const dynamoSearch = {
ExpressionAttributeValues: {
':pk2': this.createUserServicePk(phoneNumber),
':sk2': this.createUserServiceSk(),
},
IndexName: 'brand-index-2',
KeyConditionExpression: 'pk2 = :pk2 AND begins_with(sk2, :sk2)',
TableName: this.tableName,
};
const { Items } = await this.executeWithRetry(DynamoMethods.query, dynamoSearch);
const Item = Items?.[0];
return Item ? cast(Item, TUserLookupByPhone) : undefined;
} |
intl-admin-app
The changes can be found in https://github.com/rbilabs/intl-admin-app/pull/242 .
Necessary changes - summary
User Service API: Adapt GET user endpoint to also search by phone numberUser Service API: Adapt thecreate
method in user service to create alookupByPhoneNumber
record if a phone number is informedUser Service API: Adaptupdate-user
lambda to update or create alookupByPhoneNumber
record if the phone number changedUser Service API: Add aisPhoneNumberVerified
field tolookupByPhoneNumber
interface. This is important to avoid impactinghttps://rbictg.atlassian.net/wiki/spaces/EGMT/pages/4329078785/Solution+Phone+Number+Authentication+for+BK+SA#Customer-support-toolUser packages: ChangegetByPhoneNumber
to use User Service API instead of directly accessing the databaseAdmin App Backend: Create a GraphQL query to request customers by phone numberAdmin App Frontend: Add the option to search customers by phone using the new queryDynamoDB: Develop a migration script to createlookupByPhoneNumber
for existing customers
Diagrams
Search customer by phone sequence diagram:
...
Necessary changes - details
intl-user-service
Include theisVerified
field inIUserLookupByPhone
Interface:https://github.com/rbilabs/intl-user-service/blob/master/src/users/user-lookup-by-phone.repository.ts#L25-L30
Code Block |
---|
export interface IUserLookupByPhone { pk: string; pk2: string; sk: string; sk2: string; isVerified: boolean; } |
CreatelookupByPhoneNumber
record after creating the user in dynamo inside thepre-signup
lambda, but only if a phone number is informed:https://github.com/rbilabs/intl-user-service/blob/master/src/cognito-lambdas/pre-signup.service.ts#L135Update thelookupByPhoneNumber
record if an user update is triggered and includes the phone number:https://github.com/rbilabs/intl-user-service/blob/master/src/users/update-comm-pref.service.ts#L150Adapt the get user endpoint to have anphoneNumber
query field, that searches by phone:https://github.com/rbilabs/intl-user-service/blob/master/src/users/users.controller.ts#L124Create a LaunchDarkly Flag and request it via a backend query (https://github.com/rbilabs/intl-admin-app/blob/master/src/remote/queries/launch-darkly.ts)
intl-packages
Create the option to searchlookupByPhone
records created byuser-service
using the endpoint. Currently,getByEmail
already works this way (https://github.com/rbilabs/intl-packages/blob/master/packages/users/src/users.ts#L359).
This changes are already implemented in this git branch: https://github.com/rbilabs/intl-packages/pull/961
intl-admin-app
Create a GraphQL query that uses thesearchByPhone
method exposed by intl-packagesUpdate the UI to display the search by phone number option
These main changes are implemented in this git branch: https://github.com/rbilabs/intl-admin-app/pull/242