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:
Yuu Ottosoka
2025-07-09 20:36:07 +03:00
parent 84760349c0
commit 49f0385d00
8 changed files with 115 additions and 15 deletions

View File

@@ -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;