Auth and session middleware.

This commit is contained in:
Mike Cao 2020-07-27 23:52:14 -07:00
parent 590a70c2ff
commit d81ee3932d
14 changed files with 142 additions and 73 deletions

View file

@ -32,6 +32,16 @@ export async function getWebsite(website_uuid) {
);
}
export async function getWebsites(user_id) {
return runQuery(
prisma.website.findMany({
where: {
user_id,
},
}),
);
}
export async function createSession(website_id, data) {
return runQuery(
prisma.session.create({
@ -126,3 +136,29 @@ export async function getPageviews(website_id, start_at, end_at) {
}),
);
}
export async function getPageviewData(
website_id,
start_at,
end_at,
timezone = 'utc',
unit = 'day',
count = '*',
) {
return runQuery(
prisma.queryRaw(
`
select date_trunc('${unit}', created_at at time zone '${timezone}') t,
count(${count}) y
from pageview
where website_id=$1
and created_at between $2 and $3
group by 1
order by 1
`,
website_id,
start_at,
end_at,
),
);
}