add clickhouse route to deleteWebsite

This commit is contained in:
Francis Cao 2022-11-18 12:08:13 -08:00
parent 21072c712c
commit eaa208652d

View File

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