feat(bot): add session management and user tracking
- Implement Prisma storage adapter for Telegram session management - Add middleware to upsert Telegram user data - Extend TelegramUser model with additional fields - Add db:push command to turbo.json and package.json - Extend Prisma client with exists helper method
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
"scripts": {
|
||||
"db:generate": "prisma generate",
|
||||
"db:migrate": "prisma migrate dev --skip-generate",
|
||||
"db:deploy": "prisma migrate deploy"
|
||||
"db:deploy": "prisma migrate deploy",
|
||||
"db:push": "prisma db push"
|
||||
},
|
||||
"dependencies": {
|
||||
"@prisma/client": "^6.11.1"
|
||||
|
||||
@@ -22,9 +22,13 @@ model TelegramSession {
|
||||
}
|
||||
|
||||
model TelegramUser {
|
||||
id String @id
|
||||
username String?
|
||||
isBlocked Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
id String @id
|
||||
username String?
|
||||
isBlocked Boolean @default(false)
|
||||
firstName String?
|
||||
lastName String?
|
||||
languageCode String?
|
||||
isPremium Boolean?
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
import { PrismaClient } from "../generated/prisma";
|
||||
import { Prisma, PrismaClient as PrismaClientBase } from '../generated/prisma';
|
||||
|
||||
const globalForPrisma = global as unknown as { prisma: PrismaClient };
|
||||
export const prisma = new PrismaClientBase().$extends({
|
||||
model: {
|
||||
$allModels: {
|
||||
async exists<T>(
|
||||
this: T,
|
||||
where?: Prisma.Args<T, 'findFirst'>['where']
|
||||
): Promise<boolean> {
|
||||
const context = Prisma.getExtensionContext(this);
|
||||
const result = await (context as any).findFirst({ where });
|
||||
return result !== null;
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const prisma =
|
||||
globalForPrisma.prisma || new PrismaClient()
|
||||
|
||||
if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
|
||||
export type PrismaClient = typeof prisma;
|
||||
|
||||
Reference in New Issue
Block a user