2020-08-12 07:24:41 +02:00
|
|
|
import { getAccountById, deleteAccount } from 'lib/queries';
|
2020-08-09 11:03:37 +02:00
|
|
|
import { useAuth } from 'lib/middleware';
|
|
|
|
import { methodNotAllowed, ok, unauthorized } from 'lib/response';
|
|
|
|
|
|
|
|
export default async (req, res) => {
|
|
|
|
await useAuth(req, res);
|
|
|
|
|
|
|
|
const { is_admin } = req.auth;
|
|
|
|
const { id } = req.query;
|
|
|
|
const user_id = +id;
|
|
|
|
|
2020-09-16 18:25:14 +02:00
|
|
|
if (!is_admin) {
|
2020-09-11 22:49:43 +02:00
|
|
|
return unauthorized(res);
|
|
|
|
}
|
2020-08-09 11:03:37 +02:00
|
|
|
|
2020-09-11 22:49:43 +02:00
|
|
|
if (req.method === 'GET') {
|
|
|
|
const account = await getAccountById(user_id);
|
2020-08-09 11:03:37 +02:00
|
|
|
|
2020-09-11 22:49:43 +02:00
|
|
|
return ok(res, account);
|
2020-08-09 11:03:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (req.method === 'DELETE') {
|
2020-09-11 22:49:43 +02:00
|
|
|
await deleteAccount(user_id);
|
2020-08-09 11:03:37 +02:00
|
|
|
|
2020-09-11 22:49:43 +02:00
|
|
|
return ok(res);
|
2020-08-09 11:03:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return methodNotAllowed(res);
|
|
|
|
};
|