Skip to content

Commit

Permalink
🔧 Add suspendWorkspace script
Browse files Browse the repository at this point in the history
  • Loading branch information
baptisteArno committed Jan 2, 2024
1 parent 7ce1a4d commit 2250622
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 23 deletions.
3 changes: 2 additions & 1 deletion packages/scripts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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:*",
Expand Down
53 changes: 31 additions & 22 deletions packages/scripts/playground.ts
Original file line number Diff line number Diff line change
@@ -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()
Expand All @@ -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))

// await prisma.bannedIp.deleteMany({})

// const result = await prisma.coupon.findMany({
// where: {
// code: '',
// },
// })

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()
}
}
}
// console.log(result)
}

executePlayground()
40 changes: 40 additions & 0 deletions packages/scripts/suspendWorkspace.ts
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 2250622

Please sign in to comment.