mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 15:14:49 -06:00
fix: adjusts on prisma connections
This commit is contained in:
parent
14d10c00ec
commit
d1bc0e6150
@ -19,6 +19,7 @@
|
||||
* Update in Baileys version that fixes timeout when updating profile picture
|
||||
* Adjusts for fix timeout error on send status message
|
||||
* Chatwoot verbose logs
|
||||
* Adjusts on prisma connections
|
||||
|
||||
# 2.1.1 (2024-09-22 10:31)
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
import { InstanceDto } from '@api/dto/instance.dto';
|
||||
import { cache, waMonitor } from '@api/server.module';
|
||||
import { cache, prismaRepository, waMonitor } from '@api/server.module';
|
||||
import { CacheConf, configService } from '@config/env.config';
|
||||
import { BadRequestException, ForbiddenException, InternalServerErrorException, NotFoundException } from '@exceptions';
|
||||
import { prismaServer } from '@libs/prisma.connect';
|
||||
import { NextFunction, Request, Response } from 'express';
|
||||
|
||||
async function getInstance(instanceName: string) {
|
||||
@ -17,9 +16,7 @@ async function getInstance(instanceName: string) {
|
||||
return exists || keyExists;
|
||||
}
|
||||
|
||||
const prisma = prismaServer;
|
||||
|
||||
return exists || (await prisma.instance.findMany({ where: { name: instanceName } })).length > 0;
|
||||
return exists || (await prismaRepository.instance.findMany({ where: { name: instanceName } })).length > 0;
|
||||
} catch (error) {
|
||||
throw new InternalServerErrorException(error?.toString());
|
||||
}
|
||||
|
@ -1,16 +0,0 @@
|
||||
import { Logger } from '@config/logger.config';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
|
||||
const logger = new Logger('Prisma');
|
||||
|
||||
export const prismaServer = (() => {
|
||||
logger.verbose('connecting');
|
||||
const db = new PrismaClient();
|
||||
|
||||
process.on('beforeExit', () => {
|
||||
logger.verbose('instance destroyed');
|
||||
db.$disconnect();
|
||||
});
|
||||
|
||||
return db;
|
||||
})();
|
@ -1,12 +1,10 @@
|
||||
import { prismaRepository } from '@api/server.module';
|
||||
import { CacheService } from '@api/services/cache.service';
|
||||
import { INSTANCE_DIR } from '@config/path.config';
|
||||
import { prismaServer } from '@libs/prisma.connect';
|
||||
import { AuthenticationState, BufferJSON, initAuthCreds, WAProto as proto } from 'baileys';
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
|
||||
const prisma = prismaServer;
|
||||
|
||||
// const fixFileName = (file: string): string | undefined => {
|
||||
// if (!file) {
|
||||
// return undefined;
|
||||
@ -18,7 +16,7 @@ const prisma = prismaServer;
|
||||
|
||||
export async function keyExists(sessionId: string): Promise<any> {
|
||||
try {
|
||||
const key = await prisma.session.findUnique({ where: { sessionId: sessionId } });
|
||||
const key = await prismaRepository.session.findUnique({ where: { sessionId: sessionId } });
|
||||
return !!key;
|
||||
} catch (error) {
|
||||
return false;
|
||||
@ -29,13 +27,13 @@ export async function saveKey(sessionId: string, keyJson: any): Promise<any> {
|
||||
const exists = await keyExists(sessionId);
|
||||
try {
|
||||
if (!exists)
|
||||
return await prisma.session.create({
|
||||
return await prismaRepository.session.create({
|
||||
data: {
|
||||
sessionId: sessionId,
|
||||
creds: JSON.stringify(keyJson),
|
||||
},
|
||||
});
|
||||
await prisma.session.update({
|
||||
await prismaRepository.session.update({
|
||||
where: { sessionId: sessionId },
|
||||
data: { creds: JSON.stringify(keyJson) },
|
||||
});
|
||||
@ -48,7 +46,7 @@ export async function getAuthKey(sessionId: string): Promise<any> {
|
||||
try {
|
||||
const register = await keyExists(sessionId);
|
||||
if (!register) return null;
|
||||
const auth = await prisma.session.findUnique({ where: { sessionId: sessionId } });
|
||||
const auth = await prismaRepository.session.findUnique({ where: { sessionId: sessionId } });
|
||||
return JSON.parse(auth?.creds);
|
||||
} catch (error) {
|
||||
return null;
|
||||
@ -59,7 +57,7 @@ async function deleteAuthKey(sessionId: string): Promise<any> {
|
||||
try {
|
||||
const register = await keyExists(sessionId);
|
||||
if (!register) return;
|
||||
await prisma.session.delete({ where: { sessionId: sessionId } });
|
||||
await prismaRepository.session.delete({ where: { sessionId: sessionId } });
|
||||
} catch (error) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user