Skip to content

Commit

Permalink
Merge pull request #979 from OneCommunityGlobal/Ramakrishna_backend_5…
Browse files Browse the repository at this point in the history
…_letter_team_code_accept_numbers

Ramakrishna Updating the teamcode validation with numbers
  • Loading branch information
one-community authored Jun 13, 2024
2 parents 278945c + 065056a commit 27fb760
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/models/team.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ const team = new Schema({
default: '',
validate: {
validator(v) {
const teamCoderegex = /^([a-zA-Z]-[a-zA-Z]{3}|[a-zA-Z]{5})$|^$/;
const teamCoderegex = /^([a-zA-Z0-9]-[a-zA-Z0-9]{3,5}|[a-zA-Z0-9]{5,7})$/;
return teamCoderegex.test(v);
},
message:
'Please enter a code in the format of A-AAA or AAAAA',
'Please enter a code in the format of A-AAAA or AAAAA, with optional numbers, and a total length between 5 and 7 characters.',
},
},
});
Expand Down
17 changes: 6 additions & 11 deletions src/models/userProfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ const userProfileSchema = new Schema({
type: String,
required: true,
unique: true,
validate: [
validate({ validator: 'isEmail', message: 'Email address is invalid' }),
],
validate: [validate({ validator: 'isEmail', message: 'Email address is invalid' })],
},
copiedAiPrompt: { type: Date, default: Date.now() },
emailSubscriptions: {
Expand All @@ -77,7 +75,7 @@ const userProfileSchema = new Schema({
startDate: {
type: Date,
required: true,
default: function () {
default() {
return this.createdDate;
},
},
Expand Down Expand Up @@ -228,10 +226,11 @@ const userProfileSchema = new Schema({
default: '',
validate: {
validator(v) {
const teamCoderegex = /^([a-zA-Z]-[a-zA-Z]{3}|[a-zA-Z]{5})$|^$/;
const teamCoderegex = /^([a-zA-Z0-9]-[a-zA-Z0-9]{3,5}|[a-zA-Z0-9]{5,7})$/;
return teamCoderegex.test(v);
},
message: 'Please enter a code in the format of A-AAA or AAAAA',
message:
'Please enter a code in the format of A-AAAA or AAAAA, with optional numbers, and a total length between 5 and 7 characters.',
},
},
infoCollections: [
Expand Down Expand Up @@ -262,8 +261,4 @@ userProfileSchema.pre('save', function (next) {
.catch((error) => next(error));
});

module.exports = mongoose.model(
'userProfile',
userProfileSchema,
'userProfiles',
);
module.exports = mongoose.model('userProfile', userProfileSchema, 'userProfiles');

0 comments on commit 27fb760

Please sign in to comment.