2
0

🔧 Add suspendWorkspace script

This commit is contained in:
Baptiste Arnaud
2024-01-02 11:03:30 +01:00
parent 7ce1a4d3d1
commit 22506223a4
3 changed files with 73 additions and 23 deletions

View File

@ -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:*",

View File

@ -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[]
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,
const result = await prisma.workspace.findMany({
where: {
members: {
some: {
user: {
email: '',
},
},
},
},
include: {
members: true,
typebots: {
select: {
name: true,
riskLevel: true,
id: true,
},
},
},
})
)
)
writeFileSync('failedTypebot.json', JSON.stringify(typebot))
exit()
}
}
}
console.log(JSON.stringify(result))
// await prisma.bannedIp.deleteMany({})
// const result = await prisma.coupon.findMany({
// where: {
// code: '',
// },
// })
// console.log(result)
}
executePlayground()

View File

@ -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()