-
Notifications
You must be signed in to change notification settings - Fork 0
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
Validate confirmation Id (activityId) for Enquiries #121
Conversation
1a0d931
to
4f990a4
Compare
@@ -17,10 +17,6 @@ const { getConfig } = storeToRefs(useConfigStore()); | |||
const permissionService = new PermissionService(); | |||
const router = useRouter(); | |||
|
|||
async function ssoRequestBasicAccess() { |
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.
deleted as was triggering unused warning
Code Climate has analyzed commit 25882d0 and detected 1 issue on this pull request. Here's the issue category breakdown:
The test coverage on the diff in this pull request is 61.5% (50% is the threshold). This pull request will bring the total coverage in the repository to 43.2% (0.1% change). View more on Code Climate. |
(order: number) => { | ||
sortOrder = order; | ||
(order: number | undefined) => { | ||
order !== undefined ? (sortOrder = order) : null; |
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.
triggered this error, this fixes it:
Types of parameters 'order' and 'value' are incompatible.
Type 'number | undefined' is not assignable to type 'number'.
Type 'undefined' is not assignable to type 'number'.
206 @update:sort-order="
|
||
if (activityId) { | ||
const submission = (await submissionService.searchSubmissions({ activityId: [activityId] })).data[0]; |
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.
We could check the backend for activityId
when there are exactly 8 characters, as that's the length of it. Will save on network calls.
On another note, I think we need to think a little ahead and make checking for submissions its own endpoint instead of using searchSubmissions
. Right now, any user would be able to search our entire DB and retrieve any submission. There should be a new endpoint that only returns existence or non-existence for now.
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.
checking 8 characters now as well as if it is a hexadecimal value.
Implemented a new endpoint for checking the validility.
@@ -234,6 +234,19 @@ async function emailConfirmation(activityId: string) { | |||
}; | |||
await submissionService.emailConfirmation(emailData); | |||
} | |||
|
|||
async function checkValidility(event: Event) { |
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.
Function name is unclear. What are we checking the validity of?
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.
added ActivityId for clarity
4f990a4
to
fbd48ae
Compare
app/src/routes/v1/enquiry.ts
Outdated
@@ -69,4 +69,9 @@ router.patch( | |||
} | |||
); | |||
|
|||
//** Validates an Activity Id */ | |||
router.get('/validate/:activityId', (req: Request, res: Response, next: NextFunction): void => { |
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.
Similar blocks of code found in 3 locations. Consider refactoring.
app/src/controllers/enquiry.ts
Outdated
} | ||
const activity = await activityService.getActivity(activityId); | ||
|
||
res.status(200).json({ valid: Boolean(activity && !activity.isDeleted) }); |
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.
Is the Boolean wrapper necessary here? activity && !activity.isDeleted
should evaluate to what you're looking for.
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.
If boolean wrapping is required if/when one of the variables ends up being undefined/falsy, it would be better do do it with a double !!
as we typically want to avoid using JS boxing functions when we are forced to cast to a different type.
res.status(200).json({ valid: !!activity && !activity.isDeleted });
app/src/routes/v1/enquiry.ts
Outdated
//** Validates an Activity Id */ | ||
router.get('/validate/:activityId', (req: Request, res: Response, next: NextFunction): void => { | ||
enquiryController.validateActivityId(req, res, next); | ||
}); | ||
|
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.
Consider moving this to a new activity route. As we are not touching any enquiry logic this feels out of place here.
app/src/controllers/enquiry.ts
Outdated
} | ||
const activity = await activityService.getActivity(activityId); | ||
|
||
res.status(200).json({ valid: Boolean(activity && !activity.isDeleted) }); |
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.
If boolean wrapping is required if/when one of the variables ends up being undefined/falsy, it would be better do do it with a double !!
as we typically want to avoid using JS boxing functions when we are forced to cast to a different type.
res.status(200).json({ valid: !!activity && !activity.isDeleted });
…s and a new endpoint in backend to perform said check
fbd48ae
to
25882d0
Compare
Description
Made it so that a warning toast pops out when the confirmation id (activityId) entered by the proponent doesn't return a submissions search result.
Proponents will now be visually told that they are entering an invalid id but not stopped from doing so.
PADS-181
Types of changes
New feature (non-breaking change which adds functionality)
Checklist
Further comments