Skip to content

Commit c2f70ca

Browse files
authored
refactor(#410): (#411)
- implement codebase refactoring
1 parent 3126013 commit c2f70ca

File tree

3 files changed

+115
-85
lines changed

3 files changed

+115
-85
lines changed

src/models/profile.model.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,6 @@ const ActivitySchema = new mongoose.Schema({
1515

1616
const profileSchema = new Schema(
1717
{
18-
firstName: {
19-
type: String,
20-
},
21-
lastName: {
22-
type: String,
23-
},
24-
address: {
25-
type: String,
26-
},
27-
city: {
28-
type: String,
29-
},
30-
country: {
31-
type: String,
32-
},
33-
phoneNumber: {
34-
type: String,
35-
},
3618
biography: {
3719
type: String,
3820
},
@@ -42,12 +24,6 @@ const profileSchema = new Schema(
4224
cover: {
4325
type: String,
4426
},
45-
gender: {
46-
type: String,
47-
},
48-
dateOfBirth: {
49-
type: Date,
50-
},
5127
activity: [ActivitySchema],
5228
user: {
5329
type: mongoose.Types.ObjectId,
@@ -68,9 +44,5 @@ const profileSchema = new Schema(
6844
}
6945
)
7046

71-
profileSchema.virtual('name').get(function () {
72-
return this.firstName + ' ' + this.lastName
73-
})
74-
7547
const Profile = mongoose.model('Profile', profileSchema)
7648
export { Profile }

src/models/user.ts

Lines changed: 92 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,34 @@ export interface UserStatus {
77
reason?: string
88
date?: Date
99
}
10-
11-
export interface UserInterface {
10+
export interface OrgUserDataInterface{
1211
_id: mongoose.Types.ObjectId;
13-
email: string;
14-
password: string;
12+
orgId: mongoose.Types.ObjectId;
1513
role: string;
1614
team?: mongoose.Types.ObjectId;
1715
status: UserStatus;
1816
cohort?: mongoose.Types.ObjectId;
1917
program?: mongoose.Types.ObjectId;
20-
organizations: string[];
18+
phase?: mongoose.Types.ObjectId;
2119
pushNotifications: boolean;
2220
emailNotifications: boolean;
23-
profile?: mongoose.Types.ObjectId;
2421
ratings?: mongoose.Types.ObjectId[];
2522
}
2623

24+
export interface UserInterface {
25+
_id: mongoose.Types.ObjectId;
26+
email: string;
27+
password: string;
28+
organizations: mongoose.Types.ObjectId[];
29+
firstName: String;
30+
lastName: String;
31+
name: String;
32+
address: String;
33+
city: String;
34+
country: String;
35+
phoneNumber: String;
36+
}
37+
2738
export enum RoleOfUser {
2839
TRAINEE = 'trainee',
2940
COORDINATOR = 'coordinator',
@@ -40,6 +51,56 @@ mongoose.set('toJSON', {
4051
},
4152
})
4253

54+
const orgUserDataSchema = new Schema({
55+
orgId: {
56+
type: mongoose.Types.ObjectId,
57+
required: true,
58+
ref: 'Organization',
59+
},
60+
role: {
61+
type: String,
62+
default: 'user',
63+
},
64+
team: {
65+
type: mongoose.Types.ObjectId,
66+
required: false,
67+
ref: 'Team',
68+
},
69+
status: {
70+
status: {
71+
type: String,
72+
enum: ['active', 'drop', 'suspended'],
73+
default: 'active',
74+
},
75+
reason: String,
76+
date: {
77+
type: Date,
78+
},
79+
},
80+
cohort: {
81+
type: mongoose.Types.ObjectId,
82+
required: false,
83+
ref: 'Cohort',
84+
},
85+
program: {
86+
type: mongoose.Types.ObjectId,
87+
required: false,
88+
ref: 'Program',
89+
},
90+
phase: {
91+
type: mongoose.Types.ObjectId,
92+
required: false,
93+
ref: 'Phase',
94+
},
95+
pushNotifications: {
96+
type: Boolean,
97+
default: true,
98+
},
99+
emailNotifications: {
100+
type: Boolean,
101+
default: true,
102+
},
103+
})
43104
const userSchema = new Schema(
44105
{
45106
email: {
@@ -51,47 +112,33 @@ const userSchema = new Schema(
51112
type: String,
52113
required: true,
53114
},
54-
role: {
115+
organizations: {
116+
type: [orgUserDataSchema],
117+
required: true,
118+
},
119+
firstName: {
55120
type: String,
56-
default: 'user',
57121
},
58-
team: {
59-
type: mongoose.Types.ObjectId,
60-
required: false,
61-
ref: 'Team',
122+
lastName: {
123+
type: String,
62124
},
63-
status: {
64-
status: {
65-
type: String,
66-
enum: ['active', 'drop', 'suspended'],
67-
default: 'active',
68-
},
69-
reason: String,
70-
date: {
71-
type: Date,
72-
},
125+
address: {
126+
type: String,
73127
},
74-
cohort: {
75-
type: mongoose.Types.ObjectId,
76-
required: false,
77-
ref: 'Cohort',
128+
city: {
129+
type: String,
78130
},
79-
program: {
80-
type: mongoose.Types.ObjectId,
81-
required: false,
82-
ref: 'Program',
131+
country: {
132+
type: String,
83133
},
84-
organizations: {
85-
type: [String],
86-
required: true,
134+
phoneNumber: {
135+
type: String,
87136
},
88-
pushNotifications: {
89-
type: Boolean,
90-
default: true,
137+
gender: {
138+
type: String,
91139
},
92-
emailNotifications: {
93-
type: Boolean,
94-
default: true,
140+
dateOfBirth: {
141+
type: Date,
95142
},
96143
},
97144

@@ -101,6 +148,10 @@ const userSchema = new Schema(
101148
}
102149
)
103150

151+
userSchema.virtual('name').get(function () {
152+
return this.firstName + ' ' + this.lastName
153+
})
154+
104155
userSchema.virtual('profile', {
105156
ref: 'Profile',
106157
foreignField: 'user',
@@ -149,5 +200,6 @@ const UserRole = mongoose.model(
149200
)
150201

151202
const User = model('User', userSchema)
203+
const OrgUserData = model('OrgUserData', orgUserDataSchema)
152204

153-
export { User, UserRole }
205+
export { User, UserRole, OrgUserData }

src/schema/index.ts

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,16 @@ const Schema = gql`
6969
}
7070
type User {
7171
id: ID!
72-
role: String!
7372
email: String!
7473
password: String!
75-
profile: Profile
76-
team: Team
77-
cohort: Cohort
78-
program: Program
79-
organizations: [String!]!
80-
pushNotifications: Boolean!
81-
emailNotifications: Boolean!
82-
status: StatusType
83-
ratings: [Rating]
74+
organizations: [OrgUserData!]!
75+
firstName: String
76+
lastName: String
77+
name: String
78+
address: String
79+
city: String
80+
country: String
81+
phoneNumber: String
8482
}
8583
input RegisterInput {
8684
email: String!
@@ -112,13 +110,6 @@ const Schema = gql`
112110
id: ID!
113111
user: User!
114112
activity: [Activity]
115-
firstName: String
116-
lastName: String
117-
name: String
118-
address: String
119-
city: String
120-
country: String
121-
phoneNumber: String
122113
biography: String
123114
avatar: String
124115
cover: String
@@ -166,6 +157,21 @@ const Schema = gql`
166157
activeRepos: [String]
167158
}
168159
160+
type OrgUserData {
161+
id: ID!
162+
orgId: Organization!
163+
role: String!
164+
profile: Profile
165+
program: Program
166+
phase: Phase
167+
cohort: Cohort
168+
team: Team
169+
status: StatusType
170+
ratings: [Rating]
171+
pushNotifications: Boolean!
172+
emailNotifications: Boolean!
173+
}
174+
169175
type GitHubActivity {
170176
totalCommits: String!
171177
pullRequest: pullRequest!

0 commit comments

Comments
 (0)