2022-12-13 04:45:38 +01:00
|
|
|
import { Prisma } from '@prisma/client';
|
2023-06-01 06:46:49 +02:00
|
|
|
import cache from 'lib/cache';
|
|
|
|
import prisma from 'lib/prisma';
|
2022-07-12 23:14:36 +02:00
|
|
|
|
2023-06-01 06:46:49 +02:00
|
|
|
export async function createSession(data: Prisma.SessionCreateInput) {
|
2023-02-20 18:04:20 +01:00
|
|
|
const {
|
|
|
|
id,
|
|
|
|
websiteId,
|
|
|
|
hostname,
|
|
|
|
browser,
|
|
|
|
os,
|
|
|
|
device,
|
|
|
|
screen,
|
|
|
|
language,
|
|
|
|
country,
|
|
|
|
subdivision1,
|
|
|
|
subdivision2,
|
|
|
|
city,
|
|
|
|
} = data;
|
2022-08-27 05:21:53 +02:00
|
|
|
|
2023-06-01 06:46:49 +02:00
|
|
|
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;
|
|
|
|
});
|
2022-07-22 23:43:19 +02:00
|
|
|
}
|