mirror of
https://github.com/umami-software/umami.git
synced 2026-02-10 23:57:12 +01:00
Refactor database queries.
This commit is contained in:
parent
a248f35db2
commit
f4ca353b5c
24 changed files with 371 additions and 329 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { deleteWebsite, getWebsite } from 'lib/db';
|
||||
import { deleteWebsite, getWebsiteById } from 'lib/queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { methodNotAllowed, ok, unauthorized } from 'lib/response';
|
||||
|
||||
|
|
@ -10,13 +10,13 @@ export default async (req, res) => {
|
|||
const website_id = +id;
|
||||
|
||||
if (req.method === 'GET') {
|
||||
const website = await getWebsite({ website_id });
|
||||
const website = await getWebsiteById(website_id);
|
||||
|
||||
return ok(res, website);
|
||||
}
|
||||
|
||||
if (req.method === 'DELETE') {
|
||||
const website = await getWebsite({ website_id });
|
||||
const website = await getWebsiteById(website_id);
|
||||
|
||||
if (website.user_id === user_id || is_admin) {
|
||||
await deleteWebsite(website_id);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { getMetrics } from 'lib/db';
|
||||
import { getMetrics } from 'lib/queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { ok } from 'lib/response';
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import moment from 'moment-timezone';
|
||||
import { getPageviewData } from 'lib/db';
|
||||
import { getPageviews } from 'lib/queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { ok, badRequest } from 'lib/response';
|
||||
|
||||
|
|
@ -18,8 +18,8 @@ export default async (req, res) => {
|
|||
const end = new Date(+end_at);
|
||||
|
||||
const [pageviews, uniques] = await Promise.all([
|
||||
getPageviewData(+id, start, end, tz, unit, '*'),
|
||||
getPageviewData(+id, start, end, tz, unit, 'distinct session_id'),
|
||||
getPageviews(+id, start, end, tz, unit, '*'),
|
||||
getPageviews(+id, start, end, tz, unit, 'distinct session_id'),
|
||||
]);
|
||||
|
||||
return ok(res, { pageviews, uniques });
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import { getRankings } from 'lib/db';
|
||||
import { getRankings } from 'lib/queries';
|
||||
import { useAuth } from 'lib/middleware';
|
||||
import { ok, badRequest } from 'lib/response';
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue