'use strict';

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const gender = ['male', 'female', 'other', null];

const userSchema = new Schema({
	roles: [{type: Schema.Types.ObjectId, ref: 'role'}],
	email: {type: String, required: true, lowercase: true},

	schoolId: {type: Schema.Types.ObjectId, ref: 'school', required: true},

	firstName: {type: String, required: true},
	lastName: {type: String, required: true},

	gender: {type: String, enum: gender},

	preferences: {type: Object} // blackbox for frontend stuff like "cookies accepted"
},{
	timestamps: true
});

userSchema.methods.getPermissions = function() {
	const roleModel = require('../role/model');
	return roleModel.resolvePermissions(this.roles);
};

const userModel = mongoose.model('user', userSchema);
module.exports = userModel;

@@ -476,16 +476,42 @@
 nder%7D,%0A%0A
+%09birthday: %7Btype: Date%7D,%0A%0A
 %09prefere

add birthday to user