Skip to content

Commit d1bc0e6

Browse files
committed
fix: adjusts on prisma connections
1 parent 14d10c0 commit d1bc0e6

File tree

4 files changed

+9
-29
lines changed

4 files changed

+9
-29
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* Update in Baileys version that fixes timeout when updating profile picture
2020
* Adjusts for fix timeout error on send status message
2121
* Chatwoot verbose logs
22+
* Adjusts on prisma connections
2223

2324
# 2.1.1 (2024-09-22 10:31)
2425

src/api/guards/instance.guard.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { InstanceDto } from '@api/dto/instance.dto';
2-
import { cache, waMonitor } from '@api/server.module';
2+
import { cache, prismaRepository, waMonitor } from '@api/server.module';
33
import { CacheConf, configService } from '@config/env.config';
44
import { BadRequestException, ForbiddenException, InternalServerErrorException, NotFoundException } from '@exceptions';
5-
import { prismaServer } from '@libs/prisma.connect';
65
import { NextFunction, Request, Response } from 'express';
76

87
async function getInstance(instanceName: string) {
@@ -17,9 +16,7 @@ async function getInstance(instanceName: string) {
1716
return exists || keyExists;
1817
}
1918

20-
const prisma = prismaServer;
21-
22-
return exists || (await prisma.instance.findMany({ where: { name: instanceName } })).length > 0;
19+
return exists || (await prismaRepository.instance.findMany({ where: { name: instanceName } })).length > 0;
2320
} catch (error) {
2421
throw new InternalServerErrorException(error?.toString());
2522
}

src/libs/prisma.connect.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/utils/use-multi-file-auth-state-prisma.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1+
import { prismaRepository } from '@api/server.module';
12
import { CacheService } from '@api/services/cache.service';
23
import { INSTANCE_DIR } from '@config/path.config';
3-
import { prismaServer } from '@libs/prisma.connect';
44
import { AuthenticationState, BufferJSON, initAuthCreds, WAProto as proto } from 'baileys';
55
import fs from 'fs/promises';
66
import 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

1917
export 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

Comments
 (0)