diff --git a/packages/scripts/package.json b/packages/scripts/package.json index 9cf9e6f31..bce80c9a3 100644 --- a/packages/scripts/package.json +++ b/packages/scripts/package.json @@ -18,7 +18,8 @@ "createChatsPrices": "tsx createChatsPrices.ts", "migrateSubscriptionsToUsageBased": "tsx migrateSubscriptionsToUsageBased.ts", "importContactToBrevo": "tsx importContactToBrevo.ts", - "getUsage": "tsx getUsage.ts" + "getUsage": "tsx getUsage.ts", + "suspendWorkspace": "SKIP_ENV_CHECK=true dotenv -e ./.env.production -- tsx suspendWorkspace.ts" }, "devDependencies": { "@typebot.io/emails": "workspace:*", diff --git a/packages/scripts/playground.ts b/packages/scripts/playground.ts index e8ad9d824..1acc774ed 100644 --- a/packages/scripts/playground.ts +++ b/packages/scripts/playground.ts @@ -1,8 +1,5 @@ import { PrismaClient } from '@typebot.io/prisma' import { promptAndSetEnvironment } from './utils' -import { groupSchema } from '@typebot.io/schemas' -import { readFileSync, writeFileSync } from 'fs' -import { exit } from 'process' const executePlayground = async () => { await promptAndSetEnvironment() @@ -16,26 +13,38 @@ const executePlayground = async () => { console.log(e.duration, 'ms') }) - const typebots = JSON.parse(readFileSync('typebots.json', 'utf-8')) as any[] + const result = await prisma.workspace.findMany({ + where: { + members: { + some: { + user: { + email: '', + }, + }, + }, + }, + include: { + members: true, + typebots: { + select: { + name: true, + riskLevel: true, + id: true, + }, + }, + }, + }) + console.log(JSON.stringify(result)) - for (const typebot of typebots) { - for (const group of typebot.groups) { - const parser = groupSchema.safeParse(group) - if ('error' in parser) { - console.log( - group.id, - parser.error.issues.map((issue) => - JSON.stringify({ - message: issue.message, - path: issue.path, - }) - ) - ) - writeFileSync('failedTypebot.json', JSON.stringify(typebot)) - exit() - } - } - } + // await prisma.bannedIp.deleteMany({}) + + // const result = await prisma.coupon.findMany({ + // where: { + // code: '', + // }, + // }) + + // console.log(result) } executePlayground() diff --git a/packages/scripts/suspendWorkspace.ts b/packages/scripts/suspendWorkspace.ts new file mode 100644 index 000000000..1431c4e48 --- /dev/null +++ b/packages/scripts/suspendWorkspace.ts @@ -0,0 +1,40 @@ +import { PrismaClient } from '@typebot.io/prisma' + +const suspendWorkspace = async () => { + const prisma = new PrismaClient({ + log: [{ emit: 'event', level: 'query' }, 'info', 'warn', 'error'], + }) + + prisma.$on('query', (e) => { + console.log(e.query) + console.log(e.params) + console.log(e.duration, 'ms') + }) + + const typebot = await prisma.typebot.findUnique({ + where: { + id: '', + }, + select: { + workspaceId: true, + }, + }) + + if (!typebot) { + console.log('Typebot not found') + return + } + + const result = await prisma.workspace.update({ + where: { + id: typebot.workspaceId, + }, + data: { + isSuspended: true, + }, + }) + + console.log(JSON.stringify(result)) +} + +suspendWorkspace()