@@ -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+
2738export 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+ } )
43104const 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+
104155userSchema . virtual ( 'profile' , {
105156 ref : 'Profile' ,
106157 foreignField : 'user' ,
@@ -149,5 +200,6 @@ const UserRole = mongoose.model(
149200)
150201
151202const User = model ( 'User' , userSchema )
203+ const OrgUserData = model ( 'OrgUserData' , orgUserDataSchema )
152204
153- export { User , UserRole }
205+ export { User , UserRole , OrgUserData }
0 commit comments