Skip to content

Commit c0e16d3

Browse files
authored
Merge pull request #220 from UserOfficeProject/clean_up_user_fields
feat: removed unused user attributes
2 parents c82a9a5 + 28a8b93 commit c0e16d3

4 files changed

Lines changed: 3 additions & 127 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/validation/src/Review/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ const proposalFapReviewCommentValidationSchema = () => {
2222

2323
export const proposalGradeValidationSchema = Yup.object().shape({
2424
comment: proposalFapReviewCommentValidationSchema(),
25-
grade: Yup.string()
26-
.required(),
25+
grade: Yup.string().required(),
2726
});
2827

2928
export const proposalTechnicalReviewValidationSchema = Yup.object().shape({

packages/validation/src/User/index.spec.ts

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -139,65 +139,27 @@ describe('User validation schemas', () => {
139139
const validData = {
140140
firstname: 'John',
141141
lastname: 'Doe',
142-
gender: 'male',
143142
user_title: 'Mr',
144143
email: 'john.doe@example.com',
145144
password: 'Password123',
146145
confirmPassword: 'Password123',
147-
birthdate: new Date(1990, 1, 1),
148146
institutionId: 1,
149-
department: 'Research',
150-
position: 'Researcher',
151-
telephone: '+1234567890',
152147
};
153148
await expect(
154149
UserValidation.createUserValidationSchema.validate(validData)
155150
).resolves.toMatchObject(validData);
156151
});
157152

158-
it('should fail when user is under 18', async () => {
159-
const today = new Date();
160-
const underageDate = new Date(
161-
today.getFullYear() - 17,
162-
today.getMonth(),
163-
today.getDate()
164-
);
165-
166-
const invalidData = {
167-
firstname: 'John',
168-
lastname: 'Doe',
169-
gender: 'male',
170-
user_title: 'Mr',
171-
email: 'john.doe@example.com',
172-
password: 'Password123',
173-
confirmPassword: 'Password123',
174-
birthdate: underageDate,
175-
institutionId: 1,
176-
department: 'Research',
177-
position: 'Researcher',
178-
telephone: '+1234567890',
179-
};
180-
181-
await expect(
182-
UserValidation.createUserValidationSchema.validate(invalidData)
183-
).rejects.toThrow('You must be at least 18 years old');
184-
});
185-
186153
it('should validate with optional preferredname', async () => {
187154
const validData = {
188155
firstname: 'John',
189156
lastname: 'Doe',
190157
preferredname: 'Johnny',
191-
gender: 'male',
192158
user_title: 'Mr',
193159
email: 'john.doe@example.com',
194160
password: 'Password123',
195161
confirmPassword: 'Password123',
196-
birthdate: new Date(1990, 1, 1),
197162
institutionId: 1,
198-
department: 'Research',
199-
position: 'Researcher',
200-
telephone: '+1234567890',
201163
};
202164

203165
await expect(

packages/validation/src/User/index.ts

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export const createUserValidationSchema = Yup.object().shape({
2828
firstname: Yup.string().required().min(2).max(50),
2929
preferredname: Yup.string().notRequired().max(50),
3030
lastname: Yup.string().required().min(2).max(50),
31-
gender: Yup.string().required(),
3231
user_title: Yup.string().required(),
3332
email: Yup.string().email().required(),
3433
password: passwordValidationSchema,
@@ -41,110 +40,26 @@ export const createUserValidationSchema = Yup.object().shape({
4140
),
4241
})
4342
.notRequired(),
44-
birthdate: Yup.date()
45-
.min(new Date(1900, 1, 1), 'You are not that old')
46-
.test('DOB', 'You must be at least 18 years old', (value) => {
47-
// to keep the current behavior after @types/yup upgrade:
48-
// if value is `null` or `undefined` return true explicitly
49-
// because new Date(null | undefined) evaluates to `Invalid date`
50-
// which return NaN for getFullYear()
51-
// and Number - NaN < 18 evaluates to false
52-
if (!value) {
53-
return true;
54-
}
55-
56-
const dateOfBirth = new Date(value);
57-
const dateNow = new Date();
58-
59-
if (dateNow.getFullYear() - dateOfBirth.getFullYear() < 18) {
60-
return false;
61-
} else {
62-
return true;
63-
}
64-
})
65-
.required('Please specify your birth date'),
6643
institutionId: Yup.number().required(),
67-
department: Yup.string().min(2).max(50).required(),
68-
position: Yup.string().min(2).max(50).required(),
69-
telephone: Yup.string()
70-
.min(2)
71-
.max(30)
72-
.matches(phoneRegExp, 'telephone number is not valid')
73-
.required(),
7444
});
7545

7646
export const updateUserValidationSchema = Yup.object().shape({
7747
firstname: Yup.string().min(2).max(50).required(),
7848
preferredname: Yup.string().notRequired().max(50),
7949
lastname: Yup.string().min(2).max(50).required(),
80-
gender: Yup.string().required(),
8150
user_title: Yup.string().required(),
8251
email: Yup.string().email().required(),
83-
birthdate: Yup.date()
84-
.min(new Date(1900, 1, 1), 'You are not that old')
85-
.test('DOB', 'You must be at least 18 years old', (value) => {
86-
// to keep the current behavior after @types/yup upgrade:
87-
// if value is `null` or `undefined` return true explicitly
88-
// because new Date(null | undefined) evaluates to `Invalid date`
89-
// which return NaN for getFullYear()
90-
// and Number - NaN < 18 evaluates to false
91-
if (!value) {
92-
return true;
93-
}
94-
95-
const dateOfBirth = new Date(value);
96-
const dateNow = new Date();
97-
98-
if (dateNow.getFullYear() - dateOfBirth.getFullYear() < 18) {
99-
return false;
100-
} else {
101-
return true;
102-
}
103-
})
104-
.required('Please specify your birth date'),
10552
institutionId: Yup.number().required(),
106-
department: Yup.string().min(2).max(50).required(),
107-
position: Yup.string().min(2).max(50).required(),
108-
telephone: Yup.string()
109-
.min(2)
110-
.max(30)
111-
.matches(phoneRegExp, 'telephone number is not valid')
112-
.required(),
11353
});
11454

11555
export const updateUserValidationBackendSchema = Yup.object().shape({
11656
id: Yup.number().required(),
11757
firstname: Yup.string().min(2).max(50).notRequired(),
11858
preferredname: Yup.string().notRequired().max(50),
11959
lastname: Yup.string().min(2).max(50).notRequired(),
120-
gender: Yup.string().notRequired(),
12160
user_title: Yup.string().notRequired(),
12261
email: Yup.string().email().notRequired(),
123-
birthdate: Yup.date()
124-
.min(new Date(1900, 1, 1), 'You are not that old')
125-
.test('DOB', 'You must be at least 18 years old', (value) => {
126-
if (!value) {
127-
return true;
128-
}
129-
130-
const dateOfBirth = new Date(value);
131-
const dateNow = new Date();
132-
133-
if (dateNow.getFullYear() - dateOfBirth.getFullYear() < 18) {
134-
return false;
135-
} else {
136-
return true;
137-
}
138-
})
139-
.notRequired(),
14062
institutionId: Yup.number().notRequired(),
141-
department: Yup.string().min(2).max(50).notRequired(),
142-
position: Yup.string().min(2).max(50).notRequired(),
143-
telephone: Yup.string()
144-
.min(2)
145-
.max(30)
146-
.matches(phoneRegExp, 'telephone number is not valid')
147-
.notRequired(),
14863
});
14964

15065
export const updateUserRolesValidationSchema = Yup.object().shape({

0 commit comments

Comments
 (0)