2
0

🧐 Add updateUserEmail script

This commit is contained in:
Baptiste Arnaud
2024-01-12 10:45:48 +01:00
parent 69b113fc85
commit 409aeb12d3
5 changed files with 170 additions and 144 deletions

View File

@@ -1,24 +1,20 @@
import { PrismaClient } from '@typebot.io/prisma'
import { promptAndSetEnvironment } from './utils'
import prompts from 'prompts'
import { isEmpty } from '@typebot.io/lib'
import { isCancel, text } from '@clack/prompts'
const inspectUser = async () => {
await promptAndSetEnvironment('production')
const response = await prompts({
type: 'text',
name: 'email',
const email = await text({
message: 'User email',
})
if (isEmpty(response.email)) process.exit()
const prisma = new PrismaClient({
log: [{ emit: 'event', level: 'query' }, 'info', 'warn', 'error'],
})
if (!email || isCancel(email)) process.exit()
const prisma = new PrismaClient()
const user = await prisma.user.findFirst({
where: {
email: response.email,
email,
},
select: {
name: true,
@@ -37,7 +33,7 @@ const inspectUser = async () => {
plan: true,
members: {
where: {
user: { email: { not: response.email } },
user: { email: { not: email } },
},
},
additionalStorageIndex: true,
@@ -67,63 +63,7 @@ const inspectUser = async () => {
},
})
if (!user) {
console.log('User not found')
process.exit()
}
console.log('Name:', user.name)
console.log('Last activity:', user.lastActivityAt.toLocaleDateString())
console.log('Company:', user.company)
console.log('Onboarding categories:', user.onboardingCategories)
console.log('Total workspaces:', user.workspaces.length)
console.log('Workspaces:')
for (const workspace of user.workspaces) {
console.log(' - ID:', workspace.workspace.id)
console.log(' Name:', workspace.workspace.name)
console.log(' Plan:', workspace.workspace.plan)
console.log(' Members:', workspace.workspace.members.length + 1)
console.log(
' Additional storage:',
workspace.workspace.additionalStorageIndex
)
console.log(' Typebots:', workspace.workspace.typebots.length)
for (const typebot of workspace.workspace.typebots) {
console.log(' - Name:', typebot.name)
console.log(' Created:', typebot.createdAt.toLocaleDateString())
console.log(
' Last updated:',
typebot.updatedAt.toLocaleDateString()
)
console.log(' Risk level:', typebot.riskLevel)
console.log(
' Public ID:',
typebot.publishedTypebot?.typebot.publicId
)
console.log(
' URL:',
`https://app.typebot.io/typebots/${typebot.id}/edit`
)
if (!typebot.publishedTypebot) continue
const totalTraffic = await prisma.result.count({
where: {
typebotId: typebot.id,
isArchived: false,
},
select: {
_all: true,
hasStarted: true,
},
})
console.log(' Total traffic:', totalTraffic._all)
console.log(' Started:', totalTraffic.hasStarted)
}
}
console.log(JSON.stringify(user, null, 2))
}
inspectUser()