-
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
feat: adding JOI validiation to backend #35
Conversation
Code Climate has analyzed commit 5683bae and detected 17 issues on this pull request. Here's the issue category breakdown:
View more on Code Climate. |
9d07a5c
to
d628fe0
Compare
d628fe0
to
662d237
Compare
app/src/middleware/validation.ts
Outdated
// @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'; |
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.
Line can be removed
app/src/middleware/validation.ts
Outdated
return result ? [prop, result?.details] : undefined; | ||
}) | ||
.filter((error) => !!error) | ||
.map((x) => x as any[]); |
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.
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), |
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.
Should use an email regex validator. Ref COMS
// 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, |
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.
Can we use an Omit here instead of deletes?
delete submissionData.submissionTypes; | ||
delete submissionData.user; | ||
|
||
emit('submit', submissionData); |
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.
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()), |
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.
Remove commented code
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
662d237
to
5683bae
Compare
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
Further comments