aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models/user.js
blob: 14ffecbff1ca89ae5139a26946d1b54344fc5e12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const mongoose = require('mongoose')

// ---------------------------------------------------------------------------

const UserSchema = mongoose.Schema({
  password: String,
  username: String
})

UserSchema.path('password').required(true)
UserSchema.path('username').required(true)

UserSchema.statics = {
  getByUsernameAndPassword: getByUsernameAndPassword,
  list: list
}

mongoose.model('User', UserSchema)

// ---------------------------------------------------------------------------

function list (callback) {
  return this.find(callback)
}

function getByUsernameAndPassword (username, password) {
  return this.findOne({ username: username, password: password })
}