Skip to content

Instantly share code, notes, and snippets.

@astrotars
Created July 30, 2018 17:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astrotars/071ed3001a9fd5ae2d4d1375c245e872 to your computer and use it in GitHub Desktop.
Save astrotars/071ed3001a9fd5ae2d4d1375c245e872 to your computer and use it in GitHub Desktop.
import mongoose, { Schema } from 'mongoose';
import bcrypt from 'mongoose-bcrypt';
import timestamps from 'mongoose-timestamp';
import mongooseStringQuery from 'mongoose-string-query';
import FollowSchema from './follow';
import PinSchema from './pin';
import ListenSchema from './listen';
import PlaylistSchema from './playlist';
import jwt from 'jsonwebtoken';
import config from '../config';
import gravatar from 'gravatar';
import { getStreamClient } from '../utils/stream';
export const UserSchema = new Schema({
email: {
type: String,
lowercase: true,
trim: true,
index: true,
unique: true,
required: true
},
username: {
type: String,
lowercase: true,
trim: true,
index: true,
unique: true,
required: true
},
password: {
type: String,
required: true,
bcrypt: true
},
name: {
type: String,
trim: true,
required: true
},
bio: {
type: String,
trim: true,
default: ''
},
url: {
type: String,
trim: true,
default: ''
},
twitter: {
type: String,
trim: true,
default: ''
},
background: {
type: Number,
default: 1
},
interests: {
type: Schema.Types.Mixed,
default: []
},
preferences: {
notifications: {
daily: {
type: Boolean,
default: false
},
weekly: {
type: Boolean,
default: true
},
follows: {
type: Boolean,
default: true
}
}
},
recoveryCode: {
type: String,
trim: true,
default: ''
},
active: {
type: Boolean,
default: true
},
admin: {
type: Boolean,
default: false
}
});
UserSchema.plugin(bcrypt);
UserSchema.plugin(timestamps, {
createdAt: { index: true },
updatedAt: { index: true }
});
UserSchema.plugin(mongooseStringQuery);
UserSchema.index({ email: 1, username: 1 });
module.exports = exports = mongoose.model('User', UserSchema);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment