Refactor database queries.

This commit is contained in:
Mike Cao 2020-08-11 22:24:41 -07:00
parent a248f35db2
commit f4ca353b5c
24 changed files with 371 additions and 329 deletions

View file

@ -1,4 +1,4 @@
import { getWebsite, getSession, createSession } from 'lib/db';
import { getWebsiteByUuid, getSessionByUuid, createSession } from 'lib/queries';
import { getClientInfo } from 'lib/request';
import { uuid, isValidId, parseToken } from 'lib/crypto';
@ -19,7 +19,7 @@ export async function verifySession(req) {
if (!token || token.website_uuid !== website_uuid) {
const { userAgent, browser, os, ip, country, device } = await getClientInfo(req, payload);
const website = await getWebsite({ website_uuid });
const website = await getWebsiteByUuid(website_uuid);
if (!website) {
throw new Error(`Website not found: ${website_uuid}`);
@ -28,7 +28,7 @@ export async function verifySession(req) {
const { website_id } = website;
const session_uuid = uuid(website_id, hostname, ip, userAgent, os);
let session = await getSession({ session_uuid });
let session = await getSessionByUuid(session_uuid);
if (!session) {
session = await createSession(website_id, {