opt-cc/server/models/app-user.js

45 lines
800 B
JavaScript
Raw Normal View History

2018-03-12 09:26:44 +01:00
'use strict';
2017-05-10 11:04:06 +02:00
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const AppUserSchema = new Schema({
username: {
type: String,
required: true,
2018-03-12 09:26:44 +01:00
unique: true,
2017-05-10 11:04:06 +02:00
},
password: {
type: String,
2018-03-12 09:26:44 +01:00
required: true,
2017-05-10 11:04:06 +02:00
},
2017-06-08 19:46:36 +02:00
squad: {
type: mongoose.Schema.Types.ObjectId,
ref: 'Squad',
2018-03-12 09:26:44 +01:00
default: null,
2017-06-08 19:46:36 +02:00
},
2017-05-10 11:04:06 +02:00
permission: {
type: Number,
2018-03-12 09:26:44 +01:00
get: (v) => Math.round(v),
set: (v) => Math.round(v),
2017-05-10 11:04:06 +02:00
min: 0,
2017-06-08 13:14:53 +02:00
max: 4,
2018-03-12 09:26:44 +01:00
default: 0,
2017-06-08 16:03:20 +02:00
},
secret: {
type: String,
2018-03-12 09:26:44 +01:00
required: true,
2017-06-08 16:03:20 +02:00
},
activated: {
type: Boolean,
2018-03-12 09:26:44 +01:00
default: false,
},
2017-05-10 11:04:06 +02:00
}, {
collection: 'app_user',
2018-03-12 09:26:44 +01:00
timestamps: {createdAt: 'timestamp'},
2017-05-10 11:04:06 +02:00
});
// optional more indices
AppUserSchema.index({timestamp: 1});
module.exports = mongoose.model('AppUser', AppUserSchema);