mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 15:47:13 +01:00
Handle website delete. Added response helper functions.
This commit is contained in:
parent
0a411a9ad6
commit
c4b75e4aec
31 changed files with 314 additions and 96 deletions
|
|
@ -1,26 +1,40 @@
|
|||
import { getWebsites, updateWebsite } from 'lib/db';
|
||||
import { getWebsites, updateWebsite, createWebsite, getWebsite } from 'lib/db';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { uuid } from 'lib/crypto';
|
||||
import { ok, unauthorized, methodNotAllowed } from 'lib/response';
|
||||
|
||||
export default async (req, res) => {
|
||||
await useAuth(req, res);
|
||||
|
||||
const { user_id } = req.auth;
|
||||
const { user_id, is_admin } = req.auth;
|
||||
const { website_id } = req.body;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
const websites = await getWebsites(user_id);
|
||||
|
||||
return res.status(200).json(websites);
|
||||
return ok(res, websites);
|
||||
}
|
||||
|
||||
if (req.method === 'POST') {
|
||||
if (website_id) {
|
||||
const { name, domain } = req.body;
|
||||
const website = await updateWebsite(website_id, { name, domain });
|
||||
const { name, domain } = req.body;
|
||||
|
||||
return res.status(200).json(website);
|
||||
if (website_id) {
|
||||
const website = getWebsite(website_id);
|
||||
|
||||
if (website.user_id === user_id || is_admin) {
|
||||
await updateWebsite(website_id, { name, domain });
|
||||
|
||||
return ok(res);
|
||||
}
|
||||
|
||||
return unauthorized(res);
|
||||
} else {
|
||||
const website_uuid = uuid();
|
||||
const website = await createWebsite(user_id, { website_uuid, name, domain });
|
||||
|
||||
return ok(res, website);
|
||||
}
|
||||
}
|
||||
|
||||
return res.status(405).end();
|
||||
return methodNotAllowed(res);
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue