-
-
Notifications
You must be signed in to change notification settings - Fork 173
Test/years of experience #1121
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
Test/years of experience #1121
Changes from all commits
bce6c91
44b056c
42966cb
2be6c5e
d9bfb08
f216eca
fba1ab2
b506b6e
13aea32
80c56b6
793e524
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be only one migration file for the updates. Let me know if you still want to take this on or else we can take it over. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ALTER TABLE "user" ADD COLUMN "yearsOfExperience" varchar DEFAULT '0-1' NOT NULL; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Add constraints to the The frontend implementation restricts To align the database schema with the application's validation logic and enhance data integrity, consider updating the column definition as follows: ALTER TABLE "user"
ADD COLUMN "yearsOfExperience" varchar(20)
CHECK ("yearsOfExperience" IN ('0-1', '1-3', '3-5', '5-8', '8-12', '12+', 'Student', 'None'))
DEFAULT 'None'
NOT NULL;This modification introduces a length limit and enforces that only the specified values can be stored in the 🔗 Analysis chainConsider refining the The addition of the
Here's a suggested refinement: ALTER TABLE "user" ADD COLUMN "yearsOfExperience" varchar(20) CHECK ("yearsOfExperience" IN ('0-1', '1-3', '3-5', '5-10', '10+', 'Student', 'None')) NOT NULL DEFAULT 'None';This suggestion adds a length limit, includes a CHECK constraint for predefined options, and uses 'None' as the default value. Adjust the options and default value as needed to match your specific requirements. To ensure this change aligns with the frontend implementation, let's check the related React components: Please review the script output to ensure the backend and frontend implementations are consistent. 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check the implementation of yearsOfExperience in React components
# Test: Search for yearsOfExperience in TypeScript/JavaScript files
rg --type-add 'web:*.{ts,tsx,js,jsx}' -t web 'yearsOfExperience'
# Test: Look for dropdown or select components related to years of experience
rg --type-add 'web:*.{ts,tsx,js,jsx}' -t web -i 'dropdown|select.*years.*experience'
Length of output: 4236 |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| DO $$ BEGIN | ||
| ALTER TABLE "User" ADD COLUMN "yearsOfExperience" text; | ||
| EXCEPTION | ||
| WHEN duplicate_object THEN null; | ||
| END $$; | ||
|
|
||
| DO $$ BEGIN | ||
| ALTER TABLE "User" ADD CONSTRAINT "User_yearsOfExperience_check" | ||
| CHECK ("yearsOfExperience" IN ('0-1', '1-3', '3-5', '5-8', '8-12', '12+')); | ||
| EXCEPTION | ||
| WHEN duplicate_object THEN null; | ||
| END $$; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||||||||||||
| import z from "zod"; | ||||||||||||||||||||||||
| const yearsOfExperienceOptions = ["0-1", "1-3", "3-5", "5-8", "8-12", "12+"] as const; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| export const slideOneSchema = z.object({ | ||||||||||||||||||||||||
| name: z | ||||||||||||||||||||||||
|
|
@@ -30,6 +31,12 @@ export const slideThreeSchema = z | |||||||||||||||||||||||
| jobTitle: z.string().max(30, "Max length is 30 characters."), | ||||||||||||||||||||||||
| levelOfStudy: z.string(), | ||||||||||||||||||||||||
| course: z.string().max(30, "Max name length is 30 characters."), | ||||||||||||||||||||||||
| yearsOfExperience: z | ||||||||||||||||||||||||
| .string() | ||||||||||||||||||||||||
| .optional() | ||||||||||||||||||||||||
| .refine((val) => val === undefined || yearsOfExperienceOptions.includes(val as typeof yearsOfExperienceOptions[number]), { | ||||||||||||||||||||||||
| message: "Please select a valid years of experience.", | ||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||
|
Comment on lines
+34
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider making The implementation of Consider updating the schema to make - yearsOfExperience: z
- .string()
- .optional()
+ yearsOfExperience: z
+ .string()
.refine((val) => val === undefined || yearsOfExperienceOptions.includes(val as typeof yearsOfExperienceOptions[number]), {
message: "Please select a valid years of experience.",
}),This change will ensure the field aligns fully with the PR objectives. 📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||
| .superRefine((val, ctx) => { | ||||||||||||||||||||||||
| if ( | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
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.
🛠️ Refactor suggestion
Refactor to use
yearsOfExperienceOptionsinSelectcomponentCurrently, the options in the
Selectcomponent for "Years of experience" are hardcoded, which duplicates data and can lead to inconsistencies. Refactor to map over theyearsOfExperienceOptionsarray for better maintainability.Apply this change:
<Field className="mx-4 my-4 "> <Label>Years of experience:</Label> <Select id="years-of-experience" {...register('yearsOfExperience')} > <option value="" disabled> Select range </option> - <option value="0-1">0-1 years</option> - <option value="1-3">1-3 years</option> - <option value="3-5">3-5 years</option> - <option value="5-8">5-8 years</option> - <option value="8-12">8-12 years</option> - <option value="12+">12+ years</option> + {yearsOfExperienceOptions.map((range) => ( + <option key={range} value={range}> + {range} years + </option> + ))} </Select> {errors.yearsOfExperience && ( <ErrorMessage className="text-red-500"> {errors.yearsOfExperience.message} </ErrorMessage> )} </Field>