-function listUsers (req: express.Request, res: express.Response, next: express.NextFunction) {
- db.User.listForApi(req.query.start, req.query.count, req.query.sort)
- .then(resultList => {
- res.json(getFormatedObjects(resultList.data, resultList.total))
- })
- .catch(err => next(err))
+function getUser (req: express.Request, res: express.Response, next: express.NextFunction) {
+ return res.json((res.locals.user as UserModel).toFormattedJSON())
+}
+
+async function getUserVideoRating (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const videoId = +req.params.videoId
+ const accountId = +res.locals.oauth.token.User.Account.id
+
+ const ratingObj = await AccountVideoRateModel.load(accountId, videoId, null)
+ const rating = ratingObj ? ratingObj.type : 'none'
+
+ const json: FormattedUserVideoRate = {
+ videoId,
+ rating
+ }
+ res.json(json)
+}
+
+async function listUsers (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const resultList = await UserModel.listForApi(req.query.start, req.query.count, req.query.sort)
+
+ return res.json(getFormattedObjects(resultList.data, resultList.total))
+}
+
+async function removeUser (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const user = await UserModel.loadById(req.params.id)
+
+ await user.destroy()
+
+ return res.sendStatus(204)
+}
+
+async function updateMe (req: express.Request, res: express.Response, next: express.NextFunction) {
+ const body: UserUpdateMe = req.body
+
+ const user: UserModel = res.locals.oauth.token.user
+
+ if (body.password !== undefined) user.password = body.password
+ if (body.email !== undefined) user.email = body.email
+ if (body.displayNSFW !== undefined) user.displayNSFW = body.displayNSFW
+ if (body.autoPlayVideo !== undefined) user.autoPlayVideo = body.autoPlayVideo
+
+ await sequelizeTypescript.transaction(async t => {
+ await user.save({ transaction: t })
+
+ if (body.description !== undefined) user.Account.description = body.description
+ await user.Account.save({ transaction: t })
+
+ await sendUpdateActor(user.Account, t)
+ })
+
+ return res.sendStatus(204)