mirror of
https://github.com/kremalicious/umami.git
synced 2024-11-15 09:45:04 +01:00
34 lines
678 B
JavaScript
34 lines
678 B
JavaScript
|
import { getAccount, deleteAccount } from 'lib/db';
|
||
|
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) {
|
||
|
const account = await getAccount({ user_id });
|
||
|
|
||
|
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);
|
||
|
};
|