]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/models/user.js
Server: update dev dependencies
[github/Chocobozzz/PeerTube.git] / server / models / user.js
CommitLineData
69b0a27c
C
1const mongoose = require('mongoose')
2
9bd26629
C
3const customUsersValidators = require('../helpers/custom-validators').users
4
69b0a27c
C
5// ---------------------------------------------------------------------------
6
7const UserSchema = mongoose.Schema({
8 password: String,
9bd26629
C
9 username: String,
10 role: String
69b0a27c
C
11})
12
9bd26629
C
13UserSchema.path('password').required(customUsersValidators.isUserPasswordValid)
14UserSchema.path('username').required(customUsersValidators.isUserUsernameValid)
15UserSchema.path('role').validate(customUsersValidators.isUserRoleValid)
16
17UserSchema.methods = {
18 toFormatedJSON: toFormatedJSON
19}
69b0a27c
C
20
21UserSchema.statics = {
2f372a86 22 getByUsernameAndPassword: getByUsernameAndPassword,
9bd26629
C
23 list: list,
24 loadByUsername: loadByUsername
69b0a27c
C
25}
26
27mongoose.model('User', UserSchema)
28
29// ---------------------------------------------------------------------------
30
9bd26629
C
31function getByUsernameAndPassword (username, password) {
32 return this.findOne({ username: username, password: password })
33}
34
69b0a27c
C
35function list (callback) {
36 return this.find(callback)
37}
38
9bd26629
C
39function loadByUsername (username, callback) {
40 return this.findOne({ username: username }, callback)
41}
42
43function toFormatedJSON () {
44 return {
45 id: this._id,
46 username: this.username,
47 role: this.role
48 }
69b0a27c 49}