🔧 Add suspendWorkspace script
This commit is contained in:
@ -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:*",
|
||||
|
@ -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()
|
||||
|
40
packages/scripts/suspendWorkspace.ts
Normal file
40
packages/scripts/suspendWorkspace.ts
Normal 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()
|
Reference in New Issue
Block a user