umami/lib/query.ts

52 lines
1023 B
TypeScript
Raw Normal View History

2023-04-02 00:44:30 +02:00
import cache from 'lib/cache';
2023-04-02 02:38:35 +02:00
import { getWebsite, getSession, getUser } from 'queries';
2023-04-03 02:28:25 +02:00
import { User, Website, Session } from '@prisma/client';
2023-04-02 00:44:30 +02:00
export async function loadWebsite(websiteId: string): Promise<Website> {
let website;
if (cache.enabled) {
website = await cache.fetchWebsite(websiteId);
} else {
website = await getWebsite({ id: websiteId });
}
if (!website || website.deletedAt) {
return null;
}
return website;
}
2023-04-02 02:38:35 +02:00
2023-04-03 02:28:25 +02:00
export async function loadSession(sessionId: string): Promise<Session> {
2023-04-02 02:38:35 +02:00
let session;
if (cache.enabled) {
session = await cache.fetchSession(sessionId);
} else {
session = await getSession({ id: sessionId });
}
if (!session) {
return null;
}
return session;
}
2023-04-03 02:28:25 +02:00
export async function loadUser(userId: string): Promise<User> {
2023-04-02 02:38:35 +02:00
let user;
if (cache.enabled) {
user = await cache.fetchUser(userId);
} else {
user = await getUser({ id: userId });
}
if (!user || user.deletedAt) {
return null;
}
return user;
}