-
Notifications
You must be signed in to change notification settings - Fork 3
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(GIFT-3546): add endpoint to fetch customer data #1127
base: feat/FN-3543/integrate-with-ods
Are you sure you want to change the base?
feat(GIFT-3546): add endpoint to fetch customer data #1127
Conversation
… and update .env.sample
@@ -10,7 +10,7 @@ run-name: Executing test QA on ${{ github.repository }} 🚀 | |||
|
|||
on: | |||
pull_request: | |||
branches: [main] | |||
branches: [main, feat/FN-3543/integrate-with-ods] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
temporarily leaving this in while the feature branch is open to run tests, will remove before feature branch is merged to main
pattern: regexToString(UKEFID.PARTY_ID.REGEX), | ||
}) | ||
@Matches(UKEFID.PARTY_ID.REGEX) | ||
public customerUrn: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The endpoint and ODS refer to the entity as customer so I've used customer URN instead of party URN here but I'm happy to change back to partyUrn if people think that is more logical/consistent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Opted to just call it urn while in the namespace of customer
@ApiProperty({ | ||
description: 'The unique UKEF id of the customer', | ||
}) | ||
readonly customerUrn: string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto on customerUrn comment on the other dto
import { OdsController } from './ods.controller'; | ||
import { OdsService } from './ods.service'; | ||
|
||
describe('OdsController', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted a test to check the validation of the dto (e.g. valid when a urn matching the regex is passed through) but that would require setting up a validationPipe for this test which no other test in the codebase has done. For now I'm going to leave out to stay consistent with the other test suites but one to look at across the board
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment DTO validations are tested as part of api/e2e
tests (root/tests
). Most likely these tests are not part of github pipelines yet.
Would be nice to create api/e2e
test for osd
.
@Injectable() | ||
export class OdsService { | ||
constructor( | ||
@InjectDataSource(DATABASE.ODS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This black box magic of adding the name of the data source to pick the right one is amazing, I don't fully understand it but I like it
customerName: storedProcedureJson.results[0]?.customer_name, | ||
}; | ||
} catch (err) { | ||
if (err instanceof NotFoundException) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the catching and rethrowing feels a little clunky here but is the best way to get better logging for debugging which I think is worth it. Any recommendations on refactoring this are welcome
const queryRunner = this.odsDataSource.createQueryRunner(); | ||
try { | ||
// Use the query runner to call a stored procedure | ||
const result = await queryRunner.query( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortuantely typeorm doesn't support any calling of stored procedures outside of just a SQL query so I've written a parameterised SQL query to stop SQL injection but has to be hard coded like this
Quality Gate passedIssues Measures |
Introduction ✏️
Create an endpoint and new ODS service/controller/module to query ODS for the customer.
Added types and functionality for new endpoints for other ODS entities to be fetched in the future.
All entities from ODS will be fetched in a similar way using the same stored procedure hence lumping it all together in a single ODS service, we could look at splitting up controllers and services in the future if we feel they are getting too bloated.
No full payload validation has been done of the response from the ODS stored procedures - only validation of the fields that is required for the endpoint.
An API test will be added separately to this PR in a following PR