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", "createChatsPrices": "tsx createChatsPrices.ts",
"migrateSubscriptionsToUsageBased": "tsx migrateSubscriptionsToUsageBased.ts", "migrateSubscriptionsToUsageBased": "tsx migrateSubscriptionsToUsageBased.ts",
"importContactToBrevo": "tsx importContactToBrevo.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": { "devDependencies": {
"@typebot.io/emails": "workspace:*", "@typebot.io/emails": "workspace:*",

View File

@ -1,8 +1,5 @@
import { PrismaClient } from '@typebot.io/prisma' import { PrismaClient } from '@typebot.io/prisma'
import { promptAndSetEnvironment } from './utils' import { promptAndSetEnvironment } from './utils'
import { groupSchema } from '@typebot.io/schemas'
import { readFileSync, writeFileSync } from 'fs'
import { exit } from 'process'
const executePlayground = async () => { const executePlayground = async () => {
await promptAndSetEnvironment() await promptAndSetEnvironment()
@ -16,26 +13,38 @@ const executePlayground = async () => {
console.log(e.duration, 'ms') 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) { // await prisma.bannedIp.deleteMany({})
for (const group of typebot.groups) {
const parser = groupSchema.safeParse(group) // const result = await prisma.coupon.findMany({
if ('error' in parser) { // where: {
console.log( // code: '',
group.id, // },
parser.error.issues.map((issue) => // })
JSON.stringify({
message: issue.message, // console.log(result)
path: issue.path,
})
)
)
writeFileSync('failedTypebot.json', JSON.stringify(typebot))
exit()
}
}
}
} }
executePlayground() 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()