2019-11-16 19:25:44 -05:00
|
|
|
/* eslint-disable consistent-return */
|
|
|
|
import { Server } from '..';
|
|
|
|
import { Route } from '../../class';
|
2019-11-16 22:55:25 -05:00
|
|
|
import { Req } from '../interfaces';
|
2019-11-16 19:25:44 -05:00
|
|
|
|
|
|
|
export default class Account extends Route {
|
|
|
|
constructor(server: Server) {
|
|
|
|
super(server, { path: '/account', deprecated: false });
|
|
|
|
}
|
|
|
|
|
2019-11-16 19:51:29 -05:00
|
|
|
public bind() {
|
2019-11-16 19:25:44 -05:00
|
|
|
this.router.use(async (req, res, next) => {
|
2019-11-17 16:11:41 -05:00
|
|
|
await this.authorize(req, res, next);
|
2019-11-16 19:25:44 -05:00
|
|
|
});
|
2019-11-16 19:37:45 -05:00
|
|
|
|
2019-11-16 22:55:25 -05:00
|
|
|
this.router.get('/', async (req: Req, res) => {
|
2019-11-17 16:11:41 -05:00
|
|
|
try {
|
|
|
|
const acc: any = {};
|
|
|
|
acc.username = req.account.username;
|
|
|
|
acc.userID = req.account.userID;
|
|
|
|
acc.email = req.account.emailAddress;
|
|
|
|
acc.locked = req.account.locked;
|
|
|
|
acc.root = req.account.root;
|
|
|
|
acc.createdAt = req.account.createdAt;
|
|
|
|
acc.createdBy = req.account.createdBy;
|
|
|
|
acc.permissions = req.account.permissions;
|
|
|
|
res.status(200).json({ code: this.constants.codes.SUCCESS, message: acc });
|
|
|
|
} catch (error) {
|
|
|
|
this.handleError(error, res);
|
2019-11-21 09:39:07 -05:00
|
|
|
this.server.client.util.handleError(error);
|
2019-11-17 16:11:41 -05:00
|
|
|
}
|
2019-11-16 19:37:45 -05:00
|
|
|
});
|
2019-11-16 22:55:25 -05:00
|
|
|
|
2019-11-17 00:28:14 -05:00
|
|
|
this.router.get('/moderations/:id?', async (req: Req, res) => {
|
2019-11-17 16:11:41 -05:00
|
|
|
try {
|
|
|
|
const moderations = await this.server.client.db.Moderation.find({ username: req.account.username });
|
|
|
|
if (!moderations.length) res.sendStatus(204);
|
|
|
|
if (req.params.id) {
|
|
|
|
const filtered = moderations.filter((moderation) => moderation.logID === req.params.id);
|
|
|
|
res.status(200).json({ code: this.constants.codes.SUCCESS, message: { filtered } });
|
|
|
|
} else {
|
|
|
|
res.status(200).json({ code: this.constants.codes.SUCCESS, message: moderations });
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
this.handleError(error, res);
|
2019-11-21 09:39:07 -05:00
|
|
|
this.server.client.util.handleError(error);
|
2019-11-16 22:55:25 -05:00
|
|
|
}
|
|
|
|
});
|
2019-11-17 18:02:48 -05:00
|
|
|
|
|
|
|
this.router.get('/storage', async (req: Req, res) => {
|
|
|
|
try {
|
2019-11-17 18:13:17 -05:00
|
|
|
const data = await this.server.client.redis.get(`storage-${req.account.username}`) ? Number(await this.server.client.redis.get(`storage-${req.account.username}`)) : null;
|
2019-11-17 18:02:48 -05:00
|
|
|
res.status(200).json({ code: this.constants.codes.SUCCESS, message: data });
|
|
|
|
} catch (error) {
|
|
|
|
this.handleError(error, res);
|
2019-11-21 09:39:07 -05:00
|
|
|
this.server.client.util.handleError(error);
|
2019-11-17 18:02:48 -05:00
|
|
|
}
|
|
|
|
});
|
2019-11-16 19:25:44 -05:00
|
|
|
}
|
|
|
|
}
|