diff options
Diffstat (limited to 'server/controllers')
-rw-r--r-- | server/controllers/api/v1/users.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/server/controllers/api/v1/users.js b/server/controllers/api/v1/users.js index 704df770c..975e25e68 100644 --- a/server/controllers/api/v1/users.js +++ b/server/controllers/api/v1/users.js | |||
@@ -11,6 +11,10 @@ const logger = require('../../../helpers/logger') | |||
11 | const middlewares = require('../../../middlewares') | 11 | const middlewares = require('../../../middlewares') |
12 | const admin = middlewares.admin | 12 | const admin = middlewares.admin |
13 | const oAuth = middlewares.oauth | 13 | const oAuth = middlewares.oauth |
14 | const pagination = middlewares.pagination | ||
15 | const sort = middlewares.sort | ||
16 | const validatorsPagination = middlewares.validators.pagination | ||
17 | const validatorsSort = middlewares.validators.sort | ||
14 | const validatorsUsers = middlewares.validators.users | 18 | const validatorsUsers = middlewares.validators.users |
15 | 19 | ||
16 | const User = mongoose.model('User') | 20 | const User = mongoose.model('User') |
@@ -18,9 +22,16 @@ const Video = mongoose.model('Video') | |||
18 | 22 | ||
19 | const router = express.Router() | 23 | const router = express.Router() |
20 | 24 | ||
21 | router.get('/', listUsers) | ||
22 | router.get('/me', oAuth.authenticate, getUserInformation) | 25 | router.get('/me', oAuth.authenticate, getUserInformation) |
23 | 26 | ||
27 | router.get('/', | ||
28 | validatorsPagination.pagination, | ||
29 | validatorsSort.usersSort, | ||
30 | sort.setUsersSort, | ||
31 | pagination.setPagination, | ||
32 | listUsers | ||
33 | ) | ||
34 | |||
24 | router.post('/', | 35 | router.post('/', |
25 | oAuth.authenticate, | 36 | oAuth.authenticate, |
26 | admin.ensureIsAdmin, | 37 | admin.ensureIsAdmin, |
@@ -73,10 +84,10 @@ function getUserInformation (req, res, next) { | |||
73 | } | 84 | } |
74 | 85 | ||
75 | function listUsers (req, res, next) { | 86 | function listUsers (req, res, next) { |
76 | User.list(function (err, usersList) { | 87 | User.listForApi(req.query.start, req.query.count, req.query.sort, function (err, usersList, usersTotal) { |
77 | if (err) return next(err) | 88 | if (err) return next(err) |
78 | 89 | ||
79 | res.json(getFormatedUsers(usersList)) | 90 | res.json(getFormatedUsers(usersList, usersTotal)) |
80 | }) | 91 | }) |
81 | } | 92 | } |
82 | 93 | ||
@@ -145,7 +156,7 @@ function success (req, res, next) { | |||
145 | 156 | ||
146 | // --------------------------------------------------------------------------- | 157 | // --------------------------------------------------------------------------- |
147 | 158 | ||
148 | function getFormatedUsers (users) { | 159 | function getFormatedUsers (users, usersTotal) { |
149 | const formatedUsers = [] | 160 | const formatedUsers = [] |
150 | 161 | ||
151 | users.forEach(function (user) { | 162 | users.forEach(function (user) { |
@@ -153,6 +164,7 @@ function getFormatedUsers (users) { | |||
153 | }) | 164 | }) |
154 | 165 | ||
155 | return { | 166 | return { |
167 | total: usersTotal, | ||
156 | data: formatedUsers | 168 | data: formatedUsers |
157 | } | 169 | } |
158 | } | 170 | } |