Merge branch 'dev' into feat/um-23-new-schema

This commit is contained in:
Brian Cao 2022-11-18 18:50:19 -08:00
commit 51e2331315

View File

@ -1,6 +1,7 @@
import { Prisma, Website } from '@prisma/client';
import cache from 'lib/cache';
import prisma from 'lib/prisma';
import { runQuery, CLICKHOUSE, PRISMA } from 'lib/db';
export async function createWebsiteByUser(
userId: string,
@ -150,7 +151,14 @@ export async function getAllWebsites(): Promise<(Website & { user: string })[]>
export async function deleteWebsite(
websiteId: string,
): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
) {
return runQuery({
[PRISMA]: () => deleteWebsiteRelationalQuery(websiteId),
[CLICKHOUSE]: () => deleteWebsiteClickhouseQuery(websiteId),
});
}
async function deleteWebsiteRelationalQuery(websiteId): Promise<[Prisma.BatchPayload, Prisma.BatchPayload, Website]> {
const { client, transaction } = prisma;
return transaction([
@ -174,3 +182,12 @@ export async function deleteWebsite(
return data;
});
}
async function deleteWebsiteClickhouseQuery(websiteId): Promise<Website> {
return prisma.client.website.update({
data: {
isDeleted: true,
},
where: { id: websiteId },
});
}