const uniqueValidator = require('mongoose-unique-validator'); module.exports = mongoose => { var schema = mongoose.Schema( { username: { type: String, required: true, unique: true }, name: String, name_cn: String, email: { type: String, required: true, unique: true }, password: String, roles: [{ type: String }], mobile_phone: String, phone: String, home_phone: String, language: String, employment_status: String, status: String, title: String, title_cn: String, firstname: String, lastname: String, department: String, birth_date: String, driver_capacity: Number, date_hired: String, create_by: String, create_date: Date, edit_by: String, edit_date: Date, note: Object, salt: String, city: String, state: String, zipcode: String, group: [{ type: String }], tags: [{ type: String }], parent_id: String, site: Number }, { collection: 'staff', timestamps: true } ); schema.method("toJSON", function() { const { __v, _id, ...object } = this.toObject(); object.id = _id; return object; }); schema.plugin(uniqueValidator); const Staff = mongoose.model("staff", schema); return Staff; };