umami/queries/admin/website/createWebsite.ts

33 lines
583 B
TypeScript
Raw Normal View History

2022-11-15 21:21:14 +00:00
import { Website } from '@prisma/client';
import cache from 'lib/cache';
2022-11-15 21:21:14 +00:00
import prisma from 'lib/prisma';
2022-07-12 21:14:36 +00:00
2022-11-15 21:21:14 +00:00
export async function createWebsite(
userId: string,
data: {
id: string;
name: string;
domain: string;
shareId?: string;
},
): Promise<Website> {
2022-08-28 04:38:35 +00:00
return prisma.client.website
.create({
2022-07-12 21:14:36 +00:00
data: {
2022-11-01 06:42:37 +00:00
user: {
2022-07-12 21:14:36 +00:00
connect: {
id: userId,
2022-07-12 21:14:36 +00:00
},
},
...data,
},
2022-08-28 04:38:35 +00:00
})
.then(async data => {
if (cache.enabled) {
await cache.storeWebsite(data);
2022-08-28 04:38:35 +00:00
}
2022-08-27 03:21:53 +00:00
return data;
2022-08-28 04:38:35 +00:00
});
2022-07-12 21:14:36 +00:00
}