const mongoose = require('mongoose'); const { Schema } = mongoose; const pointSchema = new Schema({ type: { type: String, enum: ['Point'], required: true }, coordinates: { type: [Number], required: true } }); const schema = new Schema({ first_name: { type: String }, last_name: { type: String }, middle_name: { type: String }, email: { type: String, unique: true, lowercase: true }, password: { type: String , maxLength : 256 }, phone: { type: String }, phone2: { type: String }, permissions: { type: String, default: 'role_admin', enum : [ 'admin', 'role_admin', 'role_shipper', 'role_carrier', 'role_driver' ] }, gender: { type: String }, address: { type: String }, dob: { type: String }, // vehicle_status: { type: String, enum: ['Free', 'Loading', 'Moving', 'Downloading'] }, job_role: { type: String, enum : [ 'admin', 'owner', 'manager', 'driver', 'staff' ] }, employee_id: { type: String }, //EM-1000-1 EM-1000-2 company: { type: Schema.Types.ObjectId, ref: 'companies' }, branch: { type: Schema.Types.ObjectId, ref: 'branches' }, vehicle: { type: Schema.Types.ObjectId, ref: 'vehicles' }, active_load: { type: Schema.Types.ObjectId, ref: 'loads' }, categories: [{ type: Schema.Types.ObjectId, ref: 'productcategories' }], user_city: [{ type: String }], user_state: [{ type: String }], user_description: { type: String }, truck_type: [{ type: String }], last_location_lat: { type: String }, last_location_lng: { type: String }, last_location_geo: { type: pointSchema }, last_location_time: { type: Date }, isVerified: { type: Boolean }, session_token : { type : String, maxLength : 256 }, session_token_exp : { type: Date }, is_hidden: { type: Boolean, default: false }, is_deleted: { type: Boolean, default: false }, deleted_at: { type: Date }, createdAt: { type : Date, required : true, default : () => { return Date.now(); } } }); module.exports = mongoose.model( "users", schema );