umami/pages/api/account/[id].js

34 lines
687 B
JavaScript
Raw Normal View History

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;
if (req.method === 'GET') {
if (is_admin) {
2020-08-12 07:24:41 +02:00
const account = await getAccountById(user_id);
2020-08-09 11:03:37 +02:00
return ok(res, account);
}
return unauthorized(res);
}
if (req.method === 'DELETE') {
if (is_admin) {
await deleteAccount(user_id);
return ok(res);
}
return unauthorized(res);
}
return methodNotAllowed(res);
};