forked from uw-ssec/respondent-driven-sampling
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.ts
More file actions
45 lines (42 loc) · 1.32 KB
/
users.ts
File metadata and controls
45 lines (42 loc) · 1.32 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
import mongoose, { Model, Schema } from 'mongoose';
import { IUser } from '@/types/models';
import { ACTION_ENUM, SUBJECT_ENUM, CONDITION_ENUM } from '@/utils/roleDefinitions';
// User schema definition
// This schema defines the structure of the user data in the MongoDB database.
// It includes fields for employee ID, first name, last name, email, phone number,
const userSchema = new Schema<IUser>(
{
employeeId: {
type: String,
unique: true,
default: function (): string {
return `EMP${Math.floor(1000 + Math.random() * 9000)}`;
}
},
firstName: { type: String, required: true },
lastName: { type: String, required: true },
email: { type: String, required: true, unique: true },
phone: { type: String, required: true },
role: {
type: String,
enum: ['Volunteer', 'Manager', 'Admin'] as const,
required: true
},
approvalStatus: {
type: String,
enum: ['Pending', 'Approved', 'Rejected'] as const,
default: 'Pending'
},
permissions: {
type: [{
action: { type: String, enum: ACTION_ENUM, required: true },
subject: { type: String, enum: SUBJECT_ENUM, required: true },
condition: { type: String, enum: CONDITION_ENUM, required: true }
}],
default: []
}
},
{ timestamps: true }
);
const User: Model<IUser> = mongoose.model<IUser>('User', userSchema);
export default User;