<commit_before>import * as mongoose from 'mongoose'
import { IDevice } from './index'


export interface IUser {
    firstname: string
    lastname: string
    email?: string
    password?: string
    emailVerified?: boolean
    registered?: Date
    image: string
    devices: IDevice[]
}

export interface IUserModel extends IUser, mongoose.Document { }

let userSchema = new mongoose.Schema({
    firstname: String,
    lastname: String,
    email: { unique: true, type: String },
    password: String,
    emailVerified: { type: Boolean, default: false },
    registered: { type: Date, default: Date.now },
    image: String,
    devices : [{ type: mongoose.Schema.Types.ObjectId, ref: 'Device' }]
}, { usePushEach: true })

export let User = mongoose.model<IUserModel>('User', userSchema)

export let reduceUser = (user: IUserModel, keepEmail?:Boolean): IUser => {
    let u = <IUser>user.toObject()
    if (!keepEmail) {
        delete u.email
    }
    delete u.emailVerified
    delete u.password
    delete u.registered
    delete u.devices
    return u
}

export let reducedUserPopulationFields = '_id firstname lastname image devices'<commit_msg>add emailVerified field to own user<commit_after>import * as mongoose from 'mongoose'
import { IDevice } from './index'


export interface IUser {
    firstname: string
    lastname: string
    email?: string
    password?: string
    emailVerified?: boolean
    registered?: Date
    image: string
    devices: IDevice[]
}

export interface IUserModel extends IUser, mongoose.Document { }

let userSchema = new mongoose.Schema({
    firstname: String,
    lastname: String,
    email: { unique: true, type: String },
    password: String,
    emailVerified: { type: Boolean, default: false },
    registered: { type: Date, default: Date.now },
    image: String,
    devices : [{ type: mongoose.Schema.Types.ObjectId, ref: 'Device' }]
}, { usePushEach: true })

export let User = mongoose.model<IUserModel>('User', userSchema)

export let reduceUser = (user: IUserModel, keepEmail?:Boolean): IUser => {
    let u = <IUser>user.toObject()
    if (!keepEmail) {
        delete u.email
        delete u.emailVerified
    }
    delete u.password
    delete u.registered
    delete u.devices
    return u
}

export let reducedUserPopulationFields = '_id firstname lastname image devices'
{'fraction_non_alphanumeric': 0.10683760683760683, 'fraction_numerical': 0.0, 'mean_word_length': 3.433712121212121, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6686841', 'n_tokens_mistral': 696, 'n_tokens_neox': 701, 'n_words': 214}