umami/queries/analytics/session/createSession.ts
Brian Cao b484286523
Feat/um 305 unique session ch (#2065)
* Add session_data / session redis to CH.

* Add mysql migration.
2023-05-31 21:46:49 -07:00

46 lines
827 B
TypeScript

import { Prisma } from '@prisma/client';
import cache from 'lib/cache';
import prisma from 'lib/prisma';
export async function createSession(data: Prisma.SessionCreateInput) {
const {
id,
websiteId,
hostname,
browser,
os,
device,
screen,
language,
country,
subdivision1,
subdivision2,
city,
} = data;
return prisma.client.session
.create({
data: {
id,
websiteId,
hostname,
browser,
os,
device,
screen,
language,
country,
subdivision1: country && subdivision1 ? `${country}-${subdivision1}` : null,
subdivision2,
city,
},
})
.then(async data => {
if (cache.enabled) {
await cache.storeSession(data);
}
return data;
});
}