Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(FN-3163): MDM endpoints for automatically creating new DTFS customers in Salesforce #1057

Conversation

natdeanlewissoftwire
Copy link
Contributor

@natdeanlewissoftwire natdeanlewissoftwire commented Nov 8, 2024

Introduction ✏️

As part of the CCM project, if a customer does exist in SF, we are automatically creating it rather than relying on the manual process currently undertaken by Business Support Group. DTFS will send requests to a new customer/salesforce endpoint for MDM to create a customer in Salesforce. Technical documentation of this process is here

The corresponding feature-flagged DTFS pull request is here.

Resolution ✔️

This PR adds a "get or create" salesforce customer endpoint that does a few things:
Checks for an existing customer via Informatica. If none exists (or we return a legacy one):
Generates a URN from NUMGEN (if there isn't already one returned from a legacy record by Informatica, in which case we just use that).
Calls the new Dun and Bradstreet service (in a separate PR, here) to get a customer's DUNS number.
POSTs these along with the customer name and Companies House Number to Salesforce.
Returns the customer, including the URN to DTFS for deal submission.

Miscellaneous ➕

A tweak to the NUMGEN regex to allow customer URN creation, and a typo fix.
To be merged after this PR

// to ignore https issues, enable agent and rejectUnauthorized:false bellow.
httpsAgent: new https.Agent({
// Allow self signed negotiations
// rejectUnauthorized: false,
Copy link
Contributor Author

@natdeanlewissoftwire natdeanlewissoftwire Nov 11, 2024

Choose a reason for hiding this comment

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

This needs to be uncommented to work locally (due to a self-signed certificate in certificate chain: error) but on prod it should work fine... I'm not that happy with this state of things so if there's a better way that allows it to work everywhere without tweaking the code that'd be ideal.

Copy link

sonarqubecloud bot commented Dec 5, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
2 Security Hotspots

See analysis details on SonarQube Cloud

@natdeanlewissoftwire natdeanlewissoftwire changed the base branch from create-customer-endpoint-dnb-service to main December 5, 2024 15:10
@natdeanlewissoftwire natdeanlewissoftwire changed the base branch from main to create-customer-endpoint-dnb-service December 5, 2024 15:11
let dunsNumber: string = null;
try {
dunsNumber = await this.dunAndBradstreetService.getDunAndBradstreetNumberByRegistrationNumber(DTFSCustomerDto.companyRegistrationNumber);
} catch (error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this try catch is unnecessary? or does it provide any benefit?

const createdCustomer = await this.createCustomerByURNAndDUNS(DTFSCustomerDto, partyUrn, dunsNumber, isLegacyRecord);
res.status(201).json(createdCustomer);
return;
} catch (error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this try catch is unnecessary? or does it provide any benefit?

let dunsNumber: string = null;
try {
dunsNumber = await this.dunAndBradstreetService.getDunAndBradstreetNumberByRegistrationNumber(DTFSCustomerDto.companyRegistrationNumber);
} catch (error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this try catch is unnecessary? or does it provide any benefit?

const createdCustomer = await this.createCustomerByURNAndDUNS(DTFSCustomerDto, partyUrn, dunsNumber, isLegacyRecord);
res.status(201).json(createdCustomer);
return;
} catch (error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question about catch with immediate throw. Maybe this try catch is unnecessary? or does it provide any benefit?

@@ -22,4 +37,120 @@ export class CustomersService {
}),
);
}

async getOrCreateCustomer(res: Response, DTFSCustomerDto: DTFSCustomerDto): Promise<GetCustomersResponse> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is quite big, can we split it to smaller helpers to avoid too many nested if and try statements

@natdeanlewissoftwire natdeanlewissoftwire force-pushed the create-customer-endpoint-dnb-service branch from f9c18fc to a2f5db5 Compare January 6, 2025 09:51
@natdeanlewissoftwire natdeanlewissoftwire deleted the branch create-customer-endpoint-dnb-service January 6, 2025 11:09
abhi-markan pushed a commit that referenced this pull request Jan 8, 2025
… service only) (#1130)

## Introduction ✏️
As part of the CCM project, if a customer does exist in SF, we are
automatically creating it rather than relying on the manual process
currently undertaken by Business Support Group. DTFS will send requests
to a new customer/salesforce endpoint for MDM to create a customer in
Salesforce. Technical documentation of this process is
[here](https://ukef.sharepoint.com/:w:/r/sites/pmo-PRO211/Shared%20Documents/1.%20TO%20USE%20New%20file%20plan/2.%20Tranche%202/03.%20Customer%20and%20Credit%20Migration/Documents/DTFS%20%26%20Salesforce%20Integration/DTFS%20-%20SF%20Integration%20Technical%20Details.docx?d=w75ec8ca455ec492db2a912cc20cea7e7&csf=1&web=1&e=rhuzKr)

The corresponding feature-flagged DTFS pull request is
[here](UK-Export-Finance/dtfs2#4021)

## Resolution ✔️
This PR adds the Dun and Bradstreet service, and an endpoint to allow us
to GET a company from Dun and Bradstreet by their registration number
(in our case Companies House Number). This will then be used by [this
PR](#1057) as part of
the customer creation process.

## Miscellaneous ➕
To be merged before the remainder of the customer creation endpoint.

Also adds a user facing D&B endpoint, viewable in the Swagger docs:

![image](https://github.com/user-attachments/assets/09829422-4e50-4a81-807e-60651cd099a0)

---------

Co-authored-by: Nat Dean-Lewis <[email protected]>
@natdeanlewissoftwire natdeanlewissoftwire deleted the create-customer-endpoint branch January 8, 2025 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants