mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-19 03:42:23 -06:00
chore: Simplified payloads and instance endpoint
This commit is contained in:
@@ -1,40 +1,18 @@
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
import { ConfigService } from '../../config/env.config';
|
||||
import { Logger } from '../../config/logger.config';
|
||||
import { BadRequestException } from '../../exceptions';
|
||||
import { PrismaRepository } from '../repository/repository.service';
|
||||
import { WAMonitoringService } from './monitor.service';
|
||||
|
||||
export class AuthService {
|
||||
constructor(
|
||||
private readonly waMonitor: WAMonitoringService,
|
||||
private readonly configService: ConfigService,
|
||||
private readonly prismaRepository: PrismaRepository,
|
||||
) {}
|
||||
|
||||
private readonly logger = new Logger(AuthService.name);
|
||||
|
||||
private async apikey(token?: string) {
|
||||
const apikey = token ? token : v4().toUpperCase();
|
||||
|
||||
return apikey;
|
||||
}
|
||||
constructor(private readonly prismaRepository: PrismaRepository) {}
|
||||
|
||||
public async checkDuplicateToken(token: string) {
|
||||
const instances = await this.waMonitor.instanceInfo();
|
||||
const instances = await this.prismaRepository.instance.findMany({
|
||||
where: { token },
|
||||
});
|
||||
|
||||
const instance = instances.find((instance) => instance.instance.token === token);
|
||||
|
||||
if (instance) {
|
||||
if (instances.length > 0) {
|
||||
throw new BadRequestException('Token already exists');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async generateHash(token?: string) {
|
||||
const hash = await this.apikey(token);
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user