aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/controllers/api/users/my-abuses.ts
blob: 103c3d33266f60fd99627e4d63736e783d6b9745 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import express from 'express'
import { AbuseModel } from '@server/models/abuse/abuse'
import {
  abuseListForUserValidator,
  abusesSortValidator,
  asyncMiddleware,
  authenticate,
  paginationValidator,
  setDefaultPagination,
  setDefaultSort
} from '../../../middlewares'

const myAbusesRouter = express.Router()

myAbusesRouter.get('/me/abuses',
  authenticate,
  paginationValidator,
  abusesSortValidator,
  setDefaultSort,
  setDefaultPagination,
  abuseListForUserValidator,
  asyncMiddleware(listMyAbuses)
)

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

export {
  myAbusesRouter
}

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

async function listMyAbuses (req: express.Request, res: express.Response) {
  const resultList = await AbuseModel.listForUserApi({
    start: req.query.start,
    count: req.query.count,
    sort: req.query.sort,
    id: req.query.id,
    search: req.query.search,
    state: req.query.state,
    user: res.locals.oauth.token.User
  })

  return res.json({
    total: resultList.total,
    data: resultList.data.map(d => d.toFormattedUserJSON())
  })
}