aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/accounts.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/controllers/api/accounts.ts')
-rw-r--r--server/controllers/api/accounts.ts38
1 files changed, 38 insertions, 0 deletions
diff --git a/server/controllers/api/accounts.ts b/server/controllers/api/accounts.ts
new file mode 100644
index 000000000..aded581a5
--- /dev/null
+++ b/server/controllers/api/accounts.ts
@@ -0,0 +1,38 @@
1import * as express from 'express'
2import { getFormattedObjects } from '../../helpers/utils'
3import { asyncMiddleware, paginationValidator, setAccountsSort, setPagination } from '../../middlewares'
4import { accountsGetValidator, accountsSortValidator } from '../../middlewares/validators'
5import { AccountModel } from '../../models/account/account'
6
7const accountsRouter = express.Router()
8
9accountsRouter.get('/',
10 paginationValidator,
11 accountsSortValidator,
12 setAccountsSort,
13 setPagination,
14 asyncMiddleware(listAccounts)
15)
16
17accountsRouter.get('/:id',
18 asyncMiddleware(accountsGetValidator),
19 getAccount
20)
21
22// ---------------------------------------------------------------------------
23
24export {
25 accountsRouter
26}
27
28// ---------------------------------------------------------------------------
29
30function getAccount (req: express.Request, res: express.Response, next: express.NextFunction) {
31 return res.json(res.locals.account.toFormattedJSON())
32}
33
34async function listAccounts (req: express.Request, res: express.Response, next: express.NextFunction) {
35 const resultList = await AccountModel.listForApi(req.query.start, req.query.count, req.query.sort)
36
37 return res.json(getFormattedObjects(resultList.data, resultList.total))
38}