adjustis in instance controller

This commit is contained in:
Davidson Gomes 2024-06-06 18:30:45 -03:00
parent bdd1b8fa21
commit 85b0627737
2 changed files with 34 additions and 22 deletions

View File

@ -185,8 +185,6 @@ export class BaileysStartupService extends ChannelStartupService {
)
return;
await this.forceUpdateGroupMetadataCache();
setInterval(async () => {
await this.forceUpdateGroupMetadataCache();
}, 3600000);
@ -208,6 +206,12 @@ export class BaileysStartupService extends ChannelStartupService {
await this.client?.logout('Log out instance: ' + this.instanceName);
this.client?.ws?.close();
await this.prismaRepository.session.delete({
where: {
sessionId: this.instanceId,
},
});
}
public async getProfileName() {
@ -730,6 +734,7 @@ export class BaileysStartupService extends ChannelStartupService {
private readonly chatHandle = {
'chats.upsert': async (chats: Chat[]) => {
console.log('chats.upsert', chats);
const existingChatIds = await this.prismaRepository.chat.findMany({
where: { instanceId: this.instanceId },
select: { remoteJid: true },
@ -3091,7 +3096,7 @@ export class BaileysStartupService extends ChannelStartupService {
public async fetchAllGroups(getParticipants: GetParticipant) {
try {
const fetch = Object.values(await this.client.groupFetchAllParticipating());
const fetch = Object.values(await this?.client?.groupFetchAllParticipating());
let groups = [];
for (const group of fetch) {
const picture = await this.profilePicture(group.id);

View File

@ -195,12 +195,14 @@ export class WAMonitoringService {
public async cleaningUp(instanceName: string) {
if (this.db.ENABLED && this.db.SAVE_DATA.INSTANCE) {
await this.prismaRepository.instance.update({
const instance = await this.prismaRepository.instance.update({
where: { name: instanceName },
data: { connectionStatus: 'close' },
});
await this.prismaRepository.session.deleteMany({ where: { sessionId: instanceName } });
if (!instance) this.logger.error('Instance not found');
await this.prismaRepository.session.deleteMany({ where: { sessionId: instance.id } });
return;
}
@ -239,26 +241,31 @@ export class WAMonitoringService {
return;
}
const instance = await this.prismaRepository.instance.findFirst({
where: { name: instanceName },
});
await this.prismaRepository.session.deleteMany({ where: { sessionId: instanceName } });
rmSync(join(INSTANCE_DIR, instance.id), { recursive: true, force: true });
await this.prismaRepository.chat.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.contact.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.messageUpdate.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.message.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.session.deleteMany({ where: { sessionId: instance.id } });
await this.prismaRepository.integration.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.auth.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.webhook.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.chatwoot.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.proxy.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.rabbitmq.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.sqs.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.typebotSession.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.typebot.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.websocket.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.setting.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.label.deleteMany({ where: { instanceId: instanceName } });
await this.prismaRepository.chat.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.contact.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.messageUpdate.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.message.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.integration.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.auth.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.webhook.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.chatwoot.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.proxy.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.rabbitmq.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.sqs.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.typebotSession.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.typebot.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.websocket.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.setting.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.label.deleteMany({ where: { instanceId: instance.id } });
await this.prismaRepository.instance.delete({ where: { name: instanceName } });
}