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: adding JOI validiation to backend #35

Merged
merged 2 commits into from
Feb 28, 2024
Merged

Conversation

wilwong89
Copy link
Contributor

@wilwong89 wilwong89 commented Feb 23, 2024

Description

Installed JOI validation package
Added validation for the following endpoints:
document - createDocument, deleteDocument, listDocuments
note - createNote, listNotes
permit - createPermit, deletePermit, listPermits, updatePermit,
submission - getStatistics, getSubmission, editSubmission
user - searchUser

Validator files under src/validators
Middleware under src/middeleware/validation.ts

Modified frontend NoteCard, NoteModal, PermitModal to submit ISO dates for notes entries and remove extra fields
Modified frontend SubmissionForm to remove extra fields

Types of changes

New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING doc
  • I have checked that unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

Copy link

Coverage Report (Frontend)

Totals Coverage
Statements: 37.19% ( 222 / 597 )
Methods: 34.19% ( 40 / 117 )
Lines: 42.94% ( 143 / 333 )
Branches: 26.53% ( 39 / 147 )

app/src/routes/v1/submission.ts Show resolved Hide resolved
app/src/routes/v1/permit.ts Show resolved Hide resolved
app/src/routes/v1/permit.ts Show resolved Hide resolved
app/src/routes/v1/permit.ts Show resolved Hide resolved
app/src/routes/v1/permit.ts Show resolved Hide resolved
Copy link

codeclimate bot commented Feb 23, 2024

Code Climate has analyzed commit 5683bae and detected 17 issues on this pull request.

Here's the issue category breakdown:

Category Count
Duplication 17

View more on Code Climate.

Copy link

github-actions bot commented Feb 23, 2024

Coverage Report (Application)

Totals Coverage
Statements: 43.45% ( 73 / 168 )
Methods: 20.83% ( 5 / 24 )
Lines: 62.5% ( 60 / 96 )
Branches: 16.67% ( 8 / 48 )

app/src/routes/v1/note.ts Show resolved Hide resolved
app/src/routes/v1/document.ts Show resolved Hide resolved
app/src/routes/v1/document.ts Show resolved Hide resolved
app/src/routes/v1/note.ts Show resolved Hide resolved
app/src/routes/v1/user.ts Show resolved Hide resolved
app/src/routes/v1/submission.ts Show resolved Hide resolved
app/src/routes/v1/submission.ts Show resolved Hide resolved
app/src/routes/v1/permit.ts Show resolved Hide resolved
app/src/routes/v1/permit.ts Show resolved Hide resolved
app/src/routes/v1/permit.ts Show resolved Hide resolved
@wilwong89 wilwong89 marked this pull request as ready for review February 27, 2024 19:51
// @ts-expect-error api-problem lacks a defined interface; code still works fine
import Problem from 'api-problem';
import type { NextFunction, Request, Response } from '../interfaces/IExpress';
// import type { NextFunction, Request, Response } from 'express';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Line can be removed

return result ? [prop, result?.details] : undefined;
})
.filter((error) => !!error)
.map((x) => x as any[]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

any[] should be a properly defined type.

identityId: Joi.array().items(uuidv4),
idp: Joi.array().items(Joi.string().max(255)),
username: Joi.string().max(255),
email: Joi.string().max(255),
Copy link
Collaborator

@kyle1morel kyle1morel Feb 27, 2024

Choose a reason for hiding this comment

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

Should use an email regex validator. Ref COMS

Comment on lines +81 to 88
// Remove extra fields in permit that belongs to permitType
delete data.agency;
delete data.businessDomain;
delete data.sourceSystem;

// Convert form back to a proper Permit type
emit('permit:submit', {
const permitData = {
...data,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use an Omit here instead of deletes?

Comment on lines +136 to +139
delete submissionData.submissionTypes;
delete submissionData.user;

emit('submit', submissionData);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can we use an Omit here instead of deletes?

@@ -28,7 +28,7 @@ const visible = defineModel<boolean>('visible');

// Default form values
let initialFormValues: any = {
createdAt: formatDateShort(new Date().toISOString()),
createdAt: new Date(), //formatDateShort(new Date().toISOString()),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove commented code

app/src/validators/document.ts Show resolved Hide resolved
app/src/validators/note.ts Show resolved Hide resolved
app/src/validators/note.ts Show resolved Hide resolved
app/src/validators/permit.ts Outdated Show resolved Hide resolved
app/src/validators/permit.ts Show resolved Hide resolved
app/src/validators/submission.ts Show resolved Hide resolved
Installed JOI validation package
Added validation for the following endpoints:
document - createDocument, deleteDocument, listDocuments
note - createNote, listNotes
permit - createPermit, deletePermit, listPermits, updatePermit,
submission - getStatistics, getSubmission, editSubmission
user - searchUser

Validator files under src/validators
Middleware under src/middeleware/validation.ts

Modified frontend NoteCard, NoteModal, PermitModal to submit ISO dates
  for notes entries
Modified frontend SubmissionForm onSubmit JSON to match valid format
app/src/routes/v1/permit.ts Show resolved Hide resolved
app/src/routes/v1/note.ts Show resolved Hide resolved
app/src/routes/v1/submission.ts Show resolved Hide resolved
app/src/routes/v1/document.ts Show resolved Hide resolved
app/src/routes/v1/note.ts Show resolved Hide resolved
@kyle1morel kyle1morel merged commit a7a641e into master Feb 28, 2024
19 of 20 checks passed
@kyle1morel kyle1morel deleted the feat/joi-validation branch February 28, 2024 23:31
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