mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-19 11:52:20 -06:00
feat: prisma and remove mongodb
This commit is contained in:
@@ -4,7 +4,7 @@ import { Auth, configService, Database } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { ForbiddenException, UnauthorizedException } from '../../exceptions';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { mongodbRepository } from '../server.module';
|
||||
import { prismaRepository } from '../server.module';
|
||||
|
||||
const logger = new Logger('GUARD');
|
||||
|
||||
@@ -28,13 +28,18 @@ async function apikey(req: Request, _: Response, next: NextFunction) {
|
||||
|
||||
try {
|
||||
if (param?.instanceName) {
|
||||
const instanceKey = await mongodbRepository.auth.find(param.instanceName);
|
||||
if (instanceKey?.apikey === key) {
|
||||
const instance = await prismaRepository.instance.findUnique({
|
||||
where: { name: param.instanceName },
|
||||
include: { Auth: true },
|
||||
});
|
||||
if (instance.Auth?.apikey === key) {
|
||||
return next();
|
||||
}
|
||||
} else {
|
||||
if (req.originalUrl.includes('/instance/fetchInstances') && db.ENABLED) {
|
||||
const instanceByKey = await mongodbRepository.auth.findByKey(key);
|
||||
const instanceByKey = await prismaRepository.auth.findFirst({
|
||||
where: { apikey: key },
|
||||
});
|
||||
if (instanceByKey) {
|
||||
return next();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import {
|
||||
InternalServerErrorException,
|
||||
NotFoundException,
|
||||
} from '../../exceptions';
|
||||
import { mongodbServer } from '../../libs/mongodb.connect';
|
||||
import { prismaServer } from '../../libs/prisma.connect';
|
||||
import { InstanceDto } from '../dto/instance.dto';
|
||||
import { cache, waMonitor } from '../server.module';
|
||||
|
||||
@@ -28,11 +28,9 @@ async function getInstance(instanceName: string) {
|
||||
}
|
||||
|
||||
if (db.ENABLED) {
|
||||
const collection = mongodbServer
|
||||
.getClient()
|
||||
.db(db.CONNECTION.DB_PREFIX_NAME + '-instances')
|
||||
.collection(instanceName);
|
||||
return exists || (await collection.find({}).toArray()).length > 0;
|
||||
const prisma = prismaServer;
|
||||
|
||||
return exists || (await prisma.instance.findMany({ where: { name: instanceName } })).length > 0;
|
||||
}
|
||||
|
||||
return exists || existsSync(join(INSTANCE_DIR, instanceName));
|
||||
|
||||
Reference in New Issue
Block a user