mirror of
https://github.com/umami-software/umami.git
synced 2025-12-06 01:18:00 +01:00
Updated replica handling. Fixed types.
This commit is contained in:
parent
b36cd48b4a
commit
f70f98fed0
9 changed files with 83 additions and 168 deletions
|
|
@ -187,9 +187,7 @@ async function rawQuery(sql: string, data: Record<string, any>, name?: string):
|
|||
return `$${params.length}${type ?? ''}`;
|
||||
});
|
||||
|
||||
return process.env.DATABASE_REPLICA_URL
|
||||
? await client.$replica().$queryRawUnsafe(query, ...params)
|
||||
: await client.$queryRawUnsafe(query, ...params);
|
||||
return client.$queryRawUnsafe(query, ...params);
|
||||
}
|
||||
|
||||
async function pagedQuery<T>(model: string, criteria: T, filters?: QueryFilters) {
|
||||
|
|
@ -283,6 +281,7 @@ function getClient() {
|
|||
url: process.env.DATABASE_URL,
|
||||
prismaClient: PrismaClient,
|
||||
logQuery: !!process.env.LOG_QUERY,
|
||||
replicaUrl: process.env.DATABASE_REPLICA_URL,
|
||||
});
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') {
|
||||
|
|
@ -292,7 +291,7 @@ function getClient() {
|
|||
return prisma.client;
|
||||
}
|
||||
|
||||
const client = globalThis[PRISMA] || getClient();
|
||||
const client: PrismaClient = globalThis[PRISMA] || getClient();
|
||||
|
||||
export default {
|
||||
client,
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { Prisma, Link } from '@/generated/prisma/client';
|
||||
import { Prisma } from '@/generated/prisma/client';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { PageResult, QueryFilters } from '@/lib/types';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
|
||||
export async function findLink(criteria: Prisma.LinkFindUniqueArgs): Promise<Link> {
|
||||
export async function findLink(criteria: Prisma.LinkFindUniqueArgs) {
|
||||
return prisma.client.link.findUnique(criteria);
|
||||
}
|
||||
|
||||
export async function getLink(linkId: string): Promise<Link> {
|
||||
export async function getLink(linkId: string) {
|
||||
return findLink({
|
||||
where: {
|
||||
id: linkId,
|
||||
|
|
@ -14,10 +14,7 @@ export async function getLink(linkId: string): Promise<Link> {
|
|||
});
|
||||
}
|
||||
|
||||
export async function getLinks(
|
||||
criteria: Prisma.LinkFindManyArgs,
|
||||
filters: QueryFilters = {},
|
||||
): Promise<PageResult<Link[]>> {
|
||||
export async function getLinks(criteria: Prisma.LinkFindManyArgs, filters: QueryFilters = {}) {
|
||||
const { search } = filters;
|
||||
const { getSearchParameters, pagedQuery } = prisma;
|
||||
|
||||
|
|
@ -33,10 +30,7 @@ export async function getLinks(
|
|||
return pagedQuery('link', { ...criteria, where }, filters);
|
||||
}
|
||||
|
||||
export async function getUserLinks(
|
||||
userId: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Link[]>> {
|
||||
export async function getUserLinks(userId: string, filters?: QueryFilters) {
|
||||
return getLinks(
|
||||
{
|
||||
where: {
|
||||
|
|
@ -48,10 +42,7 @@ export async function getUserLinks(
|
|||
);
|
||||
}
|
||||
|
||||
export async function getTeamLinks(
|
||||
teamId: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Link[]>> {
|
||||
export async function getTeamLinks(teamId: string, filters?: QueryFilters) {
|
||||
return getLinks(
|
||||
{
|
||||
where: {
|
||||
|
|
@ -62,14 +53,14 @@ export async function getTeamLinks(
|
|||
);
|
||||
}
|
||||
|
||||
export async function createLink(data: Prisma.LinkUncheckedCreateInput): Promise<Link> {
|
||||
export async function createLink(data: Prisma.LinkUncheckedCreateInput) {
|
||||
return prisma.client.link.create({ data });
|
||||
}
|
||||
|
||||
export async function updateLink(linkId: string, data: any): Promise<Link> {
|
||||
export async function updateLink(linkId: string, data: any) {
|
||||
return prisma.client.link.update({ where: { id: linkId }, data });
|
||||
}
|
||||
|
||||
export async function deleteLink(linkId: string): Promise<Link> {
|
||||
export async function deleteLink(linkId: string) {
|
||||
return prisma.client.link.delete({ where: { id: linkId } });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import { Prisma, Pixel } from '@/generated/prisma/client';
|
||||
import { Prisma } from '@/generated/prisma/client';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { PageResult, QueryFilters } from '@/lib/types';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
|
||||
export async function findPixel(criteria: Prisma.PixelFindUniqueArgs): Promise<Pixel> {
|
||||
export async function findPixel(criteria: Prisma.PixelFindUniqueArgs) {
|
||||
return prisma.client.pixel.findUnique(criteria);
|
||||
}
|
||||
|
||||
export async function getPixel(pixelId: string): Promise<Pixel> {
|
||||
export async function getPixel(pixelId: string) {
|
||||
return findPixel({
|
||||
where: {
|
||||
id: pixelId,
|
||||
|
|
@ -14,10 +14,7 @@ export async function getPixel(pixelId: string): Promise<Pixel> {
|
|||
});
|
||||
}
|
||||
|
||||
export async function getPixels(
|
||||
criteria: Prisma.PixelFindManyArgs,
|
||||
filters: QueryFilters = {},
|
||||
): Promise<PageResult<Pixel[]>> {
|
||||
export async function getPixels(criteria: Prisma.PixelFindManyArgs, filters: QueryFilters = {}) {
|
||||
const { search } = filters;
|
||||
|
||||
const where: Prisma.PixelWhereInput = {
|
||||
|
|
@ -28,10 +25,7 @@ export async function getPixels(
|
|||
return prisma.pagedQuery('pixel', { ...criteria, where }, filters);
|
||||
}
|
||||
|
||||
export async function getUserPixels(
|
||||
userId: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Pixel[]>> {
|
||||
export async function getUserPixels(userId: string, filters?: QueryFilters) {
|
||||
return getPixels(
|
||||
{
|
||||
where: {
|
||||
|
|
@ -42,10 +36,7 @@ export async function getUserPixels(
|
|||
);
|
||||
}
|
||||
|
||||
export async function getTeamPixels(
|
||||
teamId: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Pixel[]>> {
|
||||
export async function getTeamPixels(teamId: string, filters?: QueryFilters) {
|
||||
return getPixels(
|
||||
{
|
||||
where: {
|
||||
|
|
@ -56,14 +47,14 @@ export async function getTeamPixels(
|
|||
);
|
||||
}
|
||||
|
||||
export async function createPixel(data: Prisma.PixelUncheckedCreateInput): Promise<Pixel> {
|
||||
export async function createPixel(data: Prisma.PixelUncheckedCreateInput) {
|
||||
return prisma.client.pixel.create({ data });
|
||||
}
|
||||
|
||||
export async function updatePixel(pixelId: string, data: any): Promise<Pixel> {
|
||||
export async function updatePixel(pixelId: string, data: any) {
|
||||
return prisma.client.pixel.update({ where: { id: pixelId }, data });
|
||||
}
|
||||
|
||||
export async function deletePixel(pixelId: string): Promise<Pixel> {
|
||||
export async function deletePixel(pixelId: string) {
|
||||
return prisma.client.pixel.delete({ where: { id: pixelId } });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
import { Prisma, Report } from '@/generated/prisma/client';
|
||||
import { Prisma } from '@/generated/prisma/client';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { PageResult, QueryFilters } from '@/lib/types';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
import ReportFindManyArgs = Prisma.ReportFindManyArgs;
|
||||
|
||||
async function findReport(criteria: Prisma.ReportFindUniqueArgs): Promise<Report> {
|
||||
async function findReport(criteria: Prisma.ReportFindUniqueArgs) {
|
||||
return prisma.client.report.findUnique(criteria);
|
||||
}
|
||||
|
||||
export async function getReport(reportId: string): Promise<Report> {
|
||||
export async function getReport(reportId: string) {
|
||||
return findReport({
|
||||
where: {
|
||||
id: reportId,
|
||||
|
|
@ -15,10 +15,7 @@ export async function getReport(reportId: string): Promise<Report> {
|
|||
});
|
||||
}
|
||||
|
||||
export async function getReports(
|
||||
criteria: ReportFindManyArgs,
|
||||
filters: QueryFilters = {},
|
||||
): Promise<PageResult<Report[]>> {
|
||||
export async function getReports(criteria: ReportFindManyArgs, filters: QueryFilters = {}) {
|
||||
const { search } = filters;
|
||||
|
||||
const where: Prisma.ReportWhereInput = {
|
||||
|
|
@ -48,10 +45,7 @@ export async function getReports(
|
|||
return prisma.pagedQuery('report', { ...criteria, where }, filters);
|
||||
}
|
||||
|
||||
export async function getUserReports(
|
||||
userId: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Report[]>> {
|
||||
export async function getUserReports(userId: string, filters?: QueryFilters) {
|
||||
return getReports(
|
||||
{
|
||||
where: {
|
||||
|
|
@ -70,10 +64,7 @@ export async function getUserReports(
|
|||
);
|
||||
}
|
||||
|
||||
export async function getWebsiteReports(
|
||||
websiteId: string,
|
||||
filters: QueryFilters = {},
|
||||
): Promise<PageResult<Report[]>> {
|
||||
export async function getWebsiteReports(websiteId: string, filters: QueryFilters = {}) {
|
||||
return getReports(
|
||||
{
|
||||
where: {
|
||||
|
|
@ -84,14 +75,14 @@ export async function getWebsiteReports(
|
|||
);
|
||||
}
|
||||
|
||||
export async function createReport(data: Prisma.ReportUncheckedCreateInput): Promise<Report> {
|
||||
export async function createReport(data: Prisma.ReportUncheckedCreateInput) {
|
||||
return prisma.client.report.create({ data });
|
||||
}
|
||||
|
||||
export async function updateReport(reportId: string, data: any): Promise<Report> {
|
||||
export async function updateReport(reportId: string, data: any) {
|
||||
return prisma.client.report.update({ where: { id: reportId }, data });
|
||||
}
|
||||
|
||||
export async function deleteReport(reportId: string): Promise<Report> {
|
||||
export async function deleteReport(reportId: string) {
|
||||
return prisma.client.report.delete({ where: { id: reportId } });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
import prisma from '@/lib/prisma';
|
||||
import { Prisma, Segment } from '@/generated/prisma/client';
|
||||
import { PageResult, QueryFilters } from '@/lib/types';
|
||||
import { Prisma } from '@/generated/prisma/client';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
|
||||
async function findSegment(criteria: Prisma.SegmentFindUniqueArgs): Promise<Segment> {
|
||||
return prisma.client.Segment.findUnique(criteria);
|
||||
async function findSegment(criteria: Prisma.SegmentFindUniqueArgs) {
|
||||
return prisma.client.segment.findUnique(criteria);
|
||||
}
|
||||
|
||||
export async function getSegment(segmentId: string): Promise<Segment> {
|
||||
export async function getSegment(segmentId: string) {
|
||||
return findSegment({
|
||||
where: {
|
||||
id: segmentId,
|
||||
|
|
@ -14,10 +14,7 @@ export async function getSegment(segmentId: string): Promise<Segment> {
|
|||
});
|
||||
}
|
||||
|
||||
export async function getSegments(
|
||||
criteria: Prisma.SegmentFindManyArgs,
|
||||
filters: QueryFilters,
|
||||
): Promise<PageResult<Segment[]>> {
|
||||
export async function getSegments(criteria: Prisma.SegmentFindManyArgs, filters: QueryFilters) {
|
||||
const { search } = filters;
|
||||
const { getSearchParameters, pagedQuery } = prisma;
|
||||
|
||||
|
|
@ -33,17 +30,13 @@ export async function getSegments(
|
|||
return pagedQuery('segment', { ...criteria, where }, filters);
|
||||
}
|
||||
|
||||
export async function getWebsiteSegment(websiteId: string, segmentId: string): Promise<Segment> {
|
||||
return prisma.client.Segment.findFirst({
|
||||
export async function getWebsiteSegment(websiteId: string, segmentId: string) {
|
||||
return prisma.client.segment.findFirst({
|
||||
where: { id: segmentId, websiteId },
|
||||
});
|
||||
}
|
||||
|
||||
export async function getWebsiteSegments(
|
||||
websiteId: string,
|
||||
type: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Segment[]>> {
|
||||
export async function getWebsiteSegments(websiteId: string, type: string, filters?: QueryFilters) {
|
||||
return getSegments(
|
||||
{
|
||||
where: {
|
||||
|
|
@ -55,17 +48,14 @@ export async function getWebsiteSegments(
|
|||
);
|
||||
}
|
||||
|
||||
export async function createSegment(data: Prisma.SegmentUncheckedCreateInput): Promise<Segment> {
|
||||
return prisma.client.Segment.create({ data });
|
||||
export async function createSegment(data: Prisma.SegmentUncheckedCreateInput) {
|
||||
return prisma.client.segment.create({ data });
|
||||
}
|
||||
|
||||
export async function updateSegment(
|
||||
SegmentId: string,
|
||||
data: Prisma.SegmentUpdateInput,
|
||||
): Promise<Segment> {
|
||||
return prisma.client.Segment.update({ where: { id: SegmentId }, data });
|
||||
export async function updateSegment(SegmentId: string, data: Prisma.SegmentUpdateInput) {
|
||||
return prisma.client.segment.update({ where: { id: SegmentId }, data });
|
||||
}
|
||||
|
||||
export async function deleteSegment(SegmentId: string): Promise<Segment> {
|
||||
return prisma.client.Segment.delete({ where: { id: SegmentId } });
|
||||
export async function deleteSegment(SegmentId: string) {
|
||||
return prisma.client.segment.delete({ where: { id: SegmentId } });
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,10 @@ export async function findTeam(criteria: Prisma.TeamFindUniqueArgs): Promise<Tea
|
|||
return prisma.client.team.findUnique(criteria);
|
||||
}
|
||||
|
||||
export async function getTeam(teamId: string, options: { includeMembers?: boolean } = {}) {
|
||||
export async function getTeam(
|
||||
teamId: string,
|
||||
options: { includeMembers?: boolean } = {},
|
||||
): Promise<Team> {
|
||||
const { includeMembers } = options;
|
||||
|
||||
return findTeam({
|
||||
|
|
@ -129,11 +132,9 @@ export async function updateTeam(teamId: string, data: Prisma.TeamUpdateInput):
|
|||
});
|
||||
}
|
||||
|
||||
export async function deleteTeam(
|
||||
teamId: string,
|
||||
): Promise<Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Team]>> {
|
||||
export async function deleteTeam(teamId: string) {
|
||||
const { client, transaction } = prisma;
|
||||
const cloudMode = !!process.env.CLOUD_URL;
|
||||
const cloudMode = !!process.env.CLOUD_MODE;
|
||||
|
||||
if (cloudMode) {
|
||||
return transaction([
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
import { uuid } from '@/lib/crypto';
|
||||
import { Prisma, TeamUser } from '@/generated/prisma/client';
|
||||
import { Prisma } from '@/generated/prisma/client';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { PageResult, QueryFilters } from '@/lib/types';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
import TeamUserFindManyArgs = Prisma.TeamUserFindManyArgs;
|
||||
|
||||
export async function findTeamUser(criteria: Prisma.TeamUserFindUniqueArgs): Promise<TeamUser> {
|
||||
export async function findTeamUser(criteria: Prisma.TeamUserFindUniqueArgs) {
|
||||
return prisma.client.teamUser.findUnique(criteria);
|
||||
}
|
||||
|
||||
export async function getTeamUser(teamId: string, userId: string): Promise<TeamUser> {
|
||||
export async function getTeamUser(teamId: string, userId: string) {
|
||||
return prisma.client.teamUser.findFirst({
|
||||
where: {
|
||||
teamId,
|
||||
|
|
@ -17,10 +17,7 @@ export async function getTeamUser(teamId: string, userId: string): Promise<TeamU
|
|||
});
|
||||
}
|
||||
|
||||
export async function getTeamUsers(
|
||||
criteria: TeamUserFindManyArgs,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<TeamUser[]>> {
|
||||
export async function getTeamUsers(criteria: TeamUserFindManyArgs, filters?: QueryFilters) {
|
||||
const { search } = filters;
|
||||
|
||||
const where: Prisma.TeamUserWhereInput = {
|
||||
|
|
@ -38,11 +35,7 @@ export async function getTeamUsers(
|
|||
);
|
||||
}
|
||||
|
||||
export async function createTeamUser(
|
||||
userId: string,
|
||||
teamId: string,
|
||||
role: string,
|
||||
): Promise<TeamUser> {
|
||||
export async function createTeamUser(userId: string, teamId: string, role: string) {
|
||||
return prisma.client.teamUser.create({
|
||||
data: {
|
||||
id: uuid(),
|
||||
|
|
@ -53,10 +46,7 @@ export async function createTeamUser(
|
|||
});
|
||||
}
|
||||
|
||||
export async function updateTeamUser(
|
||||
teamUserId: string,
|
||||
data: Prisma.TeamUserUpdateInput,
|
||||
): Promise<TeamUser> {
|
||||
export async function updateTeamUser(teamUserId: string, data: Prisma.TeamUserUpdateInput) {
|
||||
return prisma.client.teamUser.update({
|
||||
where: {
|
||||
id: teamUserId,
|
||||
|
|
@ -65,7 +55,7 @@ export async function updateTeamUser(
|
|||
});
|
||||
}
|
||||
|
||||
export async function deleteTeamUser(teamId: string, userId: string): Promise<Prisma.BatchPayload> {
|
||||
export async function deleteTeamUser(teamId: string, userId: string) {
|
||||
return prisma.client.teamUser.deleteMany({
|
||||
where: {
|
||||
teamId,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { Prisma, User } from '@/generated/prisma/client';
|
||||
import { Prisma } from '@/generated/prisma/client';
|
||||
import { ROLES } from '@/lib/constants';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { PageResult, Role, QueryFilters } from '@/lib/types';
|
||||
import { Role, QueryFilters } from '@/lib/types';
|
||||
import { getRandomChars } from '@/lib/generate';
|
||||
import UserFindManyArgs = Prisma.UserFindManyArgs;
|
||||
|
||||
|
|
@ -10,10 +10,7 @@ export interface GetUserOptions {
|
|||
showDeleted?: boolean;
|
||||
}
|
||||
|
||||
async function findUser(
|
||||
criteria: Prisma.UserFindUniqueArgs,
|
||||
options: GetUserOptions = {},
|
||||
): Promise<User> {
|
||||
async function findUser(criteria: Prisma.UserFindUniqueArgs, options: GetUserOptions = {}) {
|
||||
const { includePassword = false, showDeleted = false } = options;
|
||||
|
||||
return prisma.client.user.findUnique({
|
||||
|
|
@ -47,10 +44,7 @@ export async function getUserByUsername(username: string, options: GetUserOption
|
|||
return findUser({ where: { username } }, options);
|
||||
}
|
||||
|
||||
export async function getUsers(
|
||||
criteria: UserFindManyArgs,
|
||||
filters: QueryFilters = {},
|
||||
): Promise<PageResult<User[]>> {
|
||||
export async function getUsers(criteria: UserFindManyArgs, filters: QueryFilters = {}) {
|
||||
const { search } = filters;
|
||||
|
||||
const where: Prisma.UserWhereInput = {
|
||||
|
|
@ -78,11 +72,7 @@ export async function createUser(data: {
|
|||
username: string;
|
||||
password: string;
|
||||
role: Role;
|
||||
}): Promise<{
|
||||
id: string;
|
||||
username: string;
|
||||
role: string;
|
||||
}> {
|
||||
}) {
|
||||
return prisma.client.user.create({
|
||||
data,
|
||||
select: {
|
||||
|
|
@ -93,7 +83,7 @@ export async function createUser(data: {
|
|||
});
|
||||
}
|
||||
|
||||
export async function updateUser(userId: string, data: Prisma.UserUpdateInput): Promise<User> {
|
||||
export async function updateUser(userId: string, data: Prisma.UserUpdateInput) {
|
||||
return prisma.client.user.update({
|
||||
where: {
|
||||
id: userId,
|
||||
|
|
@ -108,21 +98,9 @@ export async function updateUser(userId: string, data: Prisma.UserUpdateInput):
|
|||
});
|
||||
}
|
||||
|
||||
export async function deleteUser(
|
||||
userId: string,
|
||||
): Promise<
|
||||
[
|
||||
Prisma.BatchPayload,
|
||||
Prisma.BatchPayload,
|
||||
Prisma.BatchPayload,
|
||||
Prisma.BatchPayload,
|
||||
Prisma.BatchPayload,
|
||||
Prisma.BatchPayload,
|
||||
User,
|
||||
]
|
||||
> {
|
||||
export async function deleteUser(userId: string) {
|
||||
const { client, transaction } = prisma;
|
||||
const cloudMode = !!process.env.CLOUD_URL;
|
||||
const cloudMode = !!process.env.CLOUD_MODE;
|
||||
|
||||
const websites = await client.website.findMany({
|
||||
where: { userId },
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import { Prisma, Website } from '@/generated/prisma/client';
|
||||
import { Prisma } from '@/generated/prisma/client';
|
||||
import redis from '@/lib/redis';
|
||||
import prisma from '@/lib/prisma';
|
||||
import { PageResult, QueryFilters } from '@/lib/types';
|
||||
import { QueryFilters } from '@/lib/types';
|
||||
import { ROLES } from '@/lib/constants';
|
||||
|
||||
export async function findWebsite(criteria: Prisma.WebsiteFindUniqueArgs): Promise<Website> {
|
||||
export async function findWebsite(criteria: Prisma.WebsiteFindUniqueArgs) {
|
||||
return prisma.client.website.findUnique(criteria);
|
||||
}
|
||||
|
||||
|
|
@ -25,10 +25,7 @@ export async function getSharedWebsite(shareId: string) {
|
|||
});
|
||||
}
|
||||
|
||||
export async function getWebsites(
|
||||
criteria: Prisma.WebsiteFindManyArgs,
|
||||
filters: QueryFilters,
|
||||
): Promise<PageResult<Website[]>> {
|
||||
export async function getWebsites(criteria: Prisma.WebsiteFindManyArgs, filters: QueryFilters) {
|
||||
const { search } = filters;
|
||||
const { getSearchParameters, pagedQuery } = prisma;
|
||||
|
||||
|
|
@ -46,10 +43,7 @@ export async function getWebsites(
|
|||
return pagedQuery('website', { ...criteria, where }, filters);
|
||||
}
|
||||
|
||||
export async function getAllUserWebsitesIncludingTeamOwner(
|
||||
userId: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Website[]>> {
|
||||
export async function getAllUserWebsitesIncludingTeamOwner(userId: string, filters?: QueryFilters) {
|
||||
return getWebsites(
|
||||
{
|
||||
where: {
|
||||
|
|
@ -76,10 +70,7 @@ export async function getAllUserWebsitesIncludingTeamOwner(
|
|||
);
|
||||
}
|
||||
|
||||
export async function getUserWebsites(
|
||||
userId: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Website[]>> {
|
||||
export async function getUserWebsites(userId: string, filters?: QueryFilters) {
|
||||
return getWebsites(
|
||||
{
|
||||
where: {
|
||||
|
|
@ -101,10 +92,7 @@ export async function getUserWebsites(
|
|||
);
|
||||
}
|
||||
|
||||
export async function getTeamWebsites(
|
||||
teamId: string,
|
||||
filters?: QueryFilters,
|
||||
): Promise<PageResult<Website[]>> {
|
||||
export async function getTeamWebsites(teamId: string, filters?: QueryFilters) {
|
||||
return getWebsites(
|
||||
{
|
||||
where: {
|
||||
|
|
@ -125,7 +113,7 @@ export async function getTeamWebsites(
|
|||
|
||||
export async function createWebsite(
|
||||
data: Prisma.WebsiteCreateInput | Prisma.WebsiteUncheckedCreateInput,
|
||||
): Promise<Website> {
|
||||
) {
|
||||
return prisma.client.website.create({
|
||||
data,
|
||||
});
|
||||
|
|
@ -134,7 +122,7 @@ export async function createWebsite(
|
|||
export async function updateWebsite(
|
||||
websiteId: string,
|
||||
data: Prisma.WebsiteUpdateInput | Prisma.WebsiteUncheckedUpdateInput,
|
||||
): Promise<Website> {
|
||||
) {
|
||||
return prisma.client.website.update({
|
||||
where: {
|
||||
id: websiteId,
|
||||
|
|
@ -143,11 +131,9 @@ export async function updateWebsite(
|
|||
});
|
||||
}
|
||||
|
||||
export async function resetWebsite(
|
||||
websiteId: string,
|
||||
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
|
||||
export async function resetWebsite(websiteId: string) {
|
||||
const { client, transaction } = prisma;
|
||||
const cloudMode = !!process.env.CLOUD_URL;
|
||||
const cloudMode = !!process.env.CLOUD_MODE;
|
||||
|
||||
return transaction([
|
||||
client.eventData.deleteMany({
|
||||
|
|
@ -177,11 +163,9 @@ export async function resetWebsite(
|
|||
});
|
||||
}
|
||||
|
||||
export async function deleteWebsite(
|
||||
websiteId: string,
|
||||
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
|
||||
export async function deleteWebsite(websiteId: string) {
|
||||
const { client, transaction } = prisma;
|
||||
const cloudMode = !!process.env.CLOUD_URL;
|
||||
const cloudMode = !!process.env.CLOUD_MODE;
|
||||
|
||||
return transaction([
|
||||
client.eventData.deleteMany({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue