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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -369,6 +369,15 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
status: 'closed',
|
||||
});
|
||||
|
||||
if (this.configService.get<Database>('DATABASE').ENABLED) {
|
||||
await this.prismaRepository.instance.update({
|
||||
where: { id: this.instanceId },
|
||||
data: {
|
||||
connectionStatus: 'close',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||
this.chatwootService.eventWhatsapp(
|
||||
Events.STATUS_INSTANCE,
|
||||
@@ -404,6 +413,17 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
`,
|
||||
);
|
||||
|
||||
if (this.configService.get<Database>('DATABASE').ENABLED) {
|
||||
await this.prismaRepository.instance.update({
|
||||
where: { id: this.instanceId },
|
||||
data: {
|
||||
ownerJid: this.instance.wuid,
|
||||
profilePicUrl: this.instance.profilePictureUrl,
|
||||
connectionStatus: 'open',
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
if (this.configService.get<Chatwoot>('CHATWOOT').ENABLED && this.localChatwoot.enabled) {
|
||||
this.chatwootService.eventWhatsapp(
|
||||
Events.CONNECTION_UPDATE,
|
||||
|
||||
Reference in New Issue
Block a user