Repository navigation
Expand file tree
/
Copy pathStudentProfile.ts
More file actions
87 lines (79 loc) · 2.22 KB
/
Copy pathStudentProfile.ts
File metadata and controls
87 lines (79 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import mongoose, { Document, Model, Schema } from 'mongoose';
export interface IEducation {
institution: string;
degree: string;
field: string;
startDate: string;
endDate: string;
}
export interface IExperience {
company: string;
role: string;
startDate: string;
endDate: string;
description: string;
}
export interface IStudentProfile extends Document {
githubUsername: string;
name: string;
email: string;
phone?: string;
skills: string[];
careerInterests?: string[];
graduationYear?: number;
education: IEducation[];
experience: IExperience[];
resumeUrl?: string;
resumeFileName?: string;
createdAt: Date;
updatedAt: Date;
}
const EducationSchema: Schema = new Schema({
institution: { type: String, required: true },
degree: { type: String, required: true },
field: { type: String, required: true },
startDate: { type: String, required: true },
endDate: { type: String, required: true },
});
const ExperienceSchema: Schema = new Schema({
company: { type: String, required: true },
role: { type: String, required: true },
startDate: { type: String, required: true },
endDate: { type: String, required: true },
description: { type: String, default: '' },
});
const StudentProfileSchema: Schema = new Schema({
githubUsername: {
type: String,
required: true,
unique: true,
lowercase: true,
trim: true,
},
name: { type: String, required: true },
email: { type: String, required: true },
phone: { type: String, default: '' },
skills: [{ type: String }],
careerInterests: [{ type: String }],
graduationYear: {
type: Number,
validate: {
validator: function (val: number) {
return val >= 2000 && val <= 2100;
},
message: 'Invalid graduation year',
},
},
education: [EducationSchema],
experience: [ExperienceSchema],
resumeUrl: { type: String },
resumeFileName: { type: String },
createdAt: { type: Date, default: Date.now },
updatedAt: { type: Date, default: Date.now },
});
StudentProfileSchema.pre('save', function () {
this.updatedAt = new Date();
});
export const StudentProfile: Model<IStudentProfile> =
mongoose.models.StudentProfile ||
mongoose.model<IStudentProfile>('StudentProfile', StudentProfileSchema);