1+ import { prismaRepository } from '@api/server.module' ;
12import { CacheService } from '@api/services/cache.service' ;
23import { INSTANCE_DIR } from '@config/path.config' ;
3- import { prismaServer } from '@libs/prisma.connect' ;
44import { AuthenticationState , BufferJSON , initAuthCreds , WAProto as proto } from 'baileys' ;
55import fs from 'fs/promises' ;
66import path from 'path' ;
77
8- const prisma = prismaServer ;
9-
108// const fixFileName = (file: string): string | undefined => {
119// if (!file) {
1210// return undefined;
@@ -18,7 +16,7 @@ const prisma = prismaServer;
1816
1917export async function keyExists ( sessionId : string ) : Promise < any > {
2018 try {
21- const key = await prisma . session . findUnique ( { where : { sessionId : sessionId } } ) ;
19+ const key = await prismaRepository . session . findUnique ( { where : { sessionId : sessionId } } ) ;
2220 return ! ! key ;
2321 } catch ( error ) {
2422 return false ;
@@ -29,13 +27,13 @@ export async function saveKey(sessionId: string, keyJson: any): Promise<any> {
2927 const exists = await keyExists ( sessionId ) ;
3028 try {
3129 if ( ! exists )
32- return await prisma . session . create ( {
30+ return await prismaRepository . session . create ( {
3331 data : {
3432 sessionId : sessionId ,
3533 creds : JSON . stringify ( keyJson ) ,
3634 } ,
3735 } ) ;
38- await prisma . session . update ( {
36+ await prismaRepository . session . update ( {
3937 where : { sessionId : sessionId } ,
4038 data : { creds : JSON . stringify ( keyJson ) } ,
4139 } ) ;
@@ -48,7 +46,7 @@ export async function getAuthKey(sessionId: string): Promise<any> {
4846 try {
4947 const register = await keyExists ( sessionId ) ;
5048 if ( ! register ) return null ;
51- const auth = await prisma . session . findUnique ( { where : { sessionId : sessionId } } ) ;
49+ const auth = await prismaRepository . session . findUnique ( { where : { sessionId : sessionId } } ) ;
5250 return JSON . parse ( auth ?. creds ) ;
5351 } catch ( error ) {
5452 return null ;
@@ -59,7 +57,7 @@ async function deleteAuthKey(sessionId: string): Promise<any> {
5957 try {
6058 const register = await keyExists ( sessionId ) ;
6159 if ( ! register ) return ;
62- await prisma . session . delete ( { where : { sessionId : sessionId } } ) ;
60+ await prismaRepository . session . delete ( { where : { sessionId : sessionId } } ) ;
6361 } catch ( error ) {
6462 return ;
6563 }
0 commit comments