{"size": 1031, "ext": "js", "max_stars_repo_path": "services/account/src/models/user.js", "max_stars_repo_name": "ajithpmohan/social-media-app", "max_stars_repo_stars_event_min_datetime": "2021-02-25T15:06:49.000Z", "max_stars_repo_stars_event_max_datetime": "2021-02-25T15:06:49.000Z", "max_issues_repo_path": "services/account/src/models/user.js", "max_issues_repo_name": "ajithpmohan/social-media-app", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "services/account/src/models/user.js", "max_forks_repo_name": "ajithpmohan/social-media-app", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 27.1315789474, "max_line_length": 77, "alphanum_fraction": 0.5800193986}
import { Schema, model } from 'mongoose';

const userSchema = new Schema(
  {
    name: { type: String, max_length: 48, required: true },
    email: { type: String, unique: true, max_length: 32, required: true },
    username: { type: String, unique: true, max_length: 32, required: true },
    password: { type: String, required: true },
    avatar: { data: Buffer, Contenttype: String },
    dob: { type: Date },
    isActive: { type: Boolean, required: true },
  },
  {
    timestamps: true,
    toJSON: {
      transform: (doc, ret) => {
        ret.dob = ret.dob?.toISOString() || '';
        ret.avatar = ret.avatar || '';
        ret.id = ret._id;
        delete ret._id;
        delete ret.password;
        delete ret.__v;
        return ret;
      },
    },
  },
);

// userSchema.static('findByEmail', function (email) {
//   return this.find({ email });
// });

// userSchema.static('findByUsername', function (username) {
//   return this.find({ username });
// });

export default model('User', userSchema, 'users');
