Refactor database queries.
This commit is contained in:
@@ -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';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user