aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/models
diff options
context:
space:
mode:
Diffstat (limited to 'server/models')
-rw-r--r--server/models/application.js31
-rw-r--r--server/models/user.js5
2 files changed, 36 insertions, 0 deletions
diff --git a/server/models/application.js b/server/models/application.js
new file mode 100644
index 000000000..8185f0915
--- /dev/null
+++ b/server/models/application.js
@@ -0,0 +1,31 @@
1const mongoose = require('mongoose')
2
3// ---------------------------------------------------------------------------
4
5const ApplicationSchema = mongoose.Schema({
6 mongoSchemaVersion: {
7 type: Number,
8 default: 0
9 }
10})
11
12ApplicationSchema.statics = {
13 loadMongoSchemaVersion: loadMongoSchemaVersion,
14 updateMongoSchemaVersion: updateMongoSchemaVersion
15}
16
17mongoose.model('Application', ApplicationSchema)
18
19// ---------------------------------------------------------------------------
20
21function loadMongoSchemaVersion (callback) {
22 return this.findOne({}, { mongoSchemaVersion: 1 }, function (err, data) {
23 const version = data ? data.mongoSchemaVersion : 0
24
25 return callback(err, version)
26 })
27}
28
29function updateMongoSchemaVersion (newVersion, callback) {
30 return this.update({}, { mongoSchemaVersion: newVersion }, callback)
31}
diff --git a/server/models/user.js b/server/models/user.js
index db6f1765b..c2c8807f0 100644
--- a/server/models/user.js
+++ b/server/models/user.js
@@ -28,6 +28,7 @@ UserSchema.methods = {
28UserSchema.statics = { 28UserSchema.statics = {
29 countTotal: countTotal, 29 countTotal: countTotal,
30 getByUsername: getByUsername, 30 getByUsername: getByUsername,
31 list: list,
31 listForApi: listForApi, 32 listForApi: listForApi,
32 loadById: loadById, 33 loadById: loadById,
33 loadByUsername: loadByUsername 34 loadByUsername: loadByUsername
@@ -71,6 +72,10 @@ function getByUsername (username) {
71 return this.findOne({ username: username }) 72 return this.findOne({ username: username })
72} 73}
73 74
75function list (callback) {
76 return this.find(callback)
77}
78
74function listForApi (start, count, sort, callback) { 79function listForApi (start, count, sort, callback) {
75 const query = {} 80 const query = {}
76 return modelUtils.listForApiWithCount.call(this, query, start, count, sort, callback) 81 return modelUtils.listForApiWithCount.call(this, query, start, count, sort, callback)